 Hey guys welcome back schizone episode 15 topic today is a quick one And that is generating reports automatically in assembly Before we get into that topic though, let me share with you my quarterly financial statement My three main physical assets, I have a 2018 Ford Focus SE hatchback in hot pepper red I have 28 quinoa strawberry plants Highly recommend that variety and I have a wife. I believe she's Caucasian Value of those assets is probably around 15 grand. That's mostly the car to be honest balances for the accounts 2.9 K for me 1.7 K for my wife our crack house equity in the bubble is 18 K It's gonna crash Retirement obviously. Yeah funny I'm losing we already knew this no big deal with that out of the way reports. Why are reports important? Well in this series, we're gonna do a lot of analysis scientific computing and sometimes I feel that It's better to represent the data in a concise Report like the one I just showed you instead of just a matrix output to the console, you know We're visual entities we we interpret visual data. I think better than numerical data sometimes So yeah, that's the main reason and in my opinion Although it may be cringe. I think HTML is probably the best format for a report like that. Why do I think that? Well? One it's plain text. So it's easy to write easy to open easy to read any text editor can open this kind of a file and it's portable so Pretty much everything is a browser nowadays like it says in the third point everything can Open this your toaster can open this kind of a file basically And it can be sent around email on a flash drive on a you know, whatever you want You can make this a highly portable Report file customizable. You can have custom elements. You could have text tables lists pictures videos Everything inside there custom JavaScript. That's all possible. It's super simple to generate If you if you take a look at the code in this video It's literally like just printing to a file. I mean it we've done this in the one of the first few videos in this series And lastly if down the road you have to change something and you have the report file Well, you can open the report file and make a change there really quick without having to rerun all of the The code now the beauty of an automatic report is that you can rerun the code You can tweak a parameter here and there I can go back. I can tweak You know my checking account I can tweak the values in this scatter plot and rerun the report and it will automatically regenerate this file but you know if you have a simple thing you have to change on your computer without the The binary that was used to create this particular report or the source code or whatever You can make that change in the text file. So for these reasons among others. I think that HTML is an awesome format for Reports like this for example, you can't edit a PDF file very easily, but you can edit an HTML file Okay As you can tell by now in this series I'm very partial towards linked lists and that's how I think I want to encode This kind of report structure. So basically in HTML file there's a bunch of elements And this is basically just an encoding of a linked list of those elements And so you may have a paragraph element or a header element or a raw text element Hey, for example, you can do custom CSS JavaScript in this element So for example, if I go back you see where it says Accessed on this day at this time if I refresh the page you can see that updates Because that's JavaScript, but it's embedded as a raw text element in this report So yeah, that's that it also is formatting type elements like our Horizontal lines as well as page breaks. Let's say you want to print the report out Well, let's say you want to have these elements on one page these on another page You can do that with a page break element. I have list elements. I have table elements. I have Images and videos as well as from the previous video in this series scatter plot elements so all of those are Possible elements and so in this linked list the first quad word is just For each each structure the first quad word is a pointer to the next element in the linked list and the last element would just have a Quad word of zero a null pointer in this slot then the next byte is a Number which corresponds to the type of item one through or gets zero through sixteen and Then lastly you you may have other things in the structure depending on what type of item that it is so For text structures, that is elements zero through seven All you have to do is encode that next element pointer the type the number zero through seven As well as the address of the null terminated string of the text to print in this slot If you have a format structure, that would be a Line or a page break. There is nothing else to put in besides the address of the next element and the number For list elements, you're gonna have to encode the number of elements as well as the address of each No terminated string in the list. So if you have five elements you have to encode five Quad words down here I each of them goes and points toward the string that you want to print and then table is similar But you have to have also the rows and the columns So if you had two rows three columns, you would need six quad words of Pointers for embedding videos and images. I have an embed structure you have to pass in the pixel width and height as well as the Address of the file that you want to attach and then from the previous video, we have scatter plots. So for those You have to encode the address of the scatter plot structure So besides that it's pretty simple, right? It's a link list of these elements and we may add more elements in the future and The function to generate these report is is very simple. It's called print HTML and we can see it in a second where it is and Basically, it's a void function and it returns nothing It just takes in a file descriptor of the file that you want to print this report to as Well as the linked list first element address So very simple very straightforward Now into the actual code, I've already showed you one of the examples Let me show you the second one before I show you the actual code So here is a more of an engineering related report. It says deflection of cantilever beam So if you're a mechanical engineer, you probably have seen this many times a Beam that's kind of attached at the one wall and being bent with a point load at the tip of the beam has a deflection along its axis I guess transverse to the axis of This equation basically where X is the coordinate along the beam P is the applied load L is the length of the beam and EI is bending stiffness, you know and D is the deflection in the direction of the applied load P And you can see here I've just put a list of what those things are put a table of the values and you can see I've I've done some math I've I basically evaluated this function at a bunch of points and I say well, this is the shape of the beam with these with this load applied at the tip so This is an example of a more engineering related report that you might want to generate So it's not just a matter of of jokes like this one, but you can actually generate valuable reports Which we will in this series. So Getting to the actual code The two examples are an example 15s directory, let's show you the first one really quick If I open up the code I Have to put this in light mode eventually The only includes that we have for this fancy report example are just that print HTML Function that I just described as well as the functions to open and close files And again as before the closing file function is optional, but we're going to use it just to you know Follow the rules for once So first we'll open that file With a given file name Then we will call the function print HTML with the first element in the linked list of the Report linked list in RSI So how does that look well basically you can see here all of this kind of stuff all these No, come to the string as you can see the last bite is zero and each of these elements These are things that you saw in the report, right? You can see my my car. You can see my strawberry plants. You can see The elements in the table you can see Things for the scatter plot all these things are Constituent elements of the linked list structures and then you can see down here. I have the actual Linked list so here's the first structure in the link list. It's the title structure and you can see it in codes The title so if you look db1 that corresponds with an h1 element, that's the title of the report I've selected and Sorry, you can see that it's referring to The address of an alternative string at address title and which one is that? This is q3 2023 fancy report So yeah, basically you just have a linked list down there of all of the elements and the title to the author to the date access to all the the lines all of the Lists all of the tables in the scatter plot Everything is encoded there as you would expect and If I run it it generates as you can see a dot HTML file and That we can open up and we can Refresh and you can see here that the time again is updated and this file is generated automatically The other example is a bit more involved Why is that? Well, it's because it involves evaluating that function it involves evaluating this function at 100 some odd points and so for that we have to use what we did in the previous video if you Look at example. I think it was 14c or we evaluated the polynomial It's a similar process in here except it's not a polynomial. It's it's this which I guess is a polynomial if you think about it But it's not nice and simple one. It's it's kind of a weird-looking polynomial So look in this code This one has a few more includes a lot of them are just to support our ability to Evaluate that expression So we have a heap We have our Parametric functions here to evaluate parameters to create a linear space of a design variable We have our heap initialization function allocation functions as well as that Print HTML function that this video is about Then you can see here. We have a function that basically implements that equation and that function gets evaluated in our Evaluate parameters function, which we covered Very briefly in the previous video, but I'll cover it in more detail in the future So ignore that for now if it's confusing But besides that it's all pretty much the same stuff again, you have a Bunch of an alternator strings here and actually one cool thing here is I have a math Element in HTML there are math elements and you can kind of encode formulas in it not perfect way, but Not terrible looking away. You can put exponents. You can put kind of like a Curse of looking letters. So it doesn't look terrible, but it's not great But yeah, you can encode a formula in HTML pretty nicely, which I think is pretty cool and useful for our purposes in this series And and yeah, so a bunch of crap like that. I'm not going to dive too deep into it. It's all there on the Suppository if you're curious you can take a look, but yes, if you run that code you will get a Can lever beam that HTML file and if you open that file you will get this and The beauty of this is well, what if you want to change this value? So right now under a thousand pound applied load you can see it deflects right around negative point five What if we double this applied load? Let's get let's go in that function and Let's change the number So first things first, let's change the the table element to two thousand and let's change the Actual deflection function the value of the applied load to two thousand so now if I run that code and then open run the binary and open up that Report you'll see that the applied load has doubled in the table and the deflection has doubled as you would expect for the equation in The diagram and so that's why I think reports are cool is because I can change inputs rerun the report get a new set of results and I Could print them out on my printer. I could email into somebody. It's just a much nicer way to present data than a Stupid matrix output to the console window, which is kind of a kind of a cringe thing So with that out of the way, that's what I wanted to cover in this video It was a very short video today, but we will leverage this kind of stuff Not in every video, but in some videos in future. So hope you enjoyed if you did Check the last link in the description and hang out on discord. So thanks for watching guys. See you