Anvil: Web Apps with Nothing but Python Transcripts
Chapter: Rounding out the UI
Lecture: Loading averages for compare
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
The next step to complete are compare yourself to the average person of your height and gender is to load up a bunch of averages.
0:09
You know, if you are this height and this gender here are your average heart rates and average weights and so on. I've already dropped in an app here.
0:18
It's very similar to the Fitnessd client at least the terminal command line version of it. So this is in the GitHub Repo for you to work with.
0:27
But let's go and have a quick look. I guess we could clean up some things here. So what it's going to do is it's going to go to the service
0:34
and see if the averages exist and not re-upload them because then we'd end up with weird duplicates. And then it's going to load some CSV data.
0:42
So if you look over here, I've just going to the internet and found some probably highly inaccurate
0:47
or at least maybe tilted data around gender and height and heart rates and things like this. Oh, it just says height and weight.
0:56
They're just height and weight over here. And then we're going to take we have 10000 rows of this and then we're going to process it
1:03
and come up with averages. If you're 71 point something inches tall then this is the average weight of these measurements. If you're 72, and so on.
1:13
And then we're going to upload those really simply here. It's using the same authentication mechanism as before.
1:20
Here's where it's computing the averages. And then we just did to not upload some when we're testing. This is kind of useless line now.
1:27
We're going to go and upload those to the service and what we've done is we've added another load average function over an.
1:36
So let's look at that real quick. So down here, we have a data loader service and I've moved the authentication step
1:44
that we wrote before from management sorry from the API, over into the separate modules so that data loader in API can use it.
1:51
And we're just going to upload a bunch of weights heights, genders and heart rate information and save that as an average, as I've described before.
2:00
There won't be too many of them. Once we average out, it's like 40-some, 41 something like this. We also want to know are there any averages.
2:09
Right, so what you're going to do is we're actually on that compare page only show the compare results
2:15
if I even attempt to continue if there are some averages uploaded, okay. So if we run it now, then we go to compare
2:24
it says, sorry, you don't have any information about a male who's five feet 11. Actually I've done a little bit more work
2:31
to work with these API end points here in this compare 'cause not a lot of sense for you watching me do this the whole time.
2:39
So let's just a quick look. So it comes in and it's going to ask for your averages and let's see what else does it Use this count thing.
2:49
So what it's going to do is it's going to ask for your average. This is a function on the server side that says I'm this tall, I'm this gender.
2:57
Do you have an average for me 'cause maybe, you know like I said we're just randomly grabbing a bunch of measurements and turning those into averages.
3:03
So we might not have one for you which would be unfortunate and you might, may or may not have measurements so if you have measurements in an average
3:10
then we're going to build this out here. And we're going to hide and show these cards. I also added two little quick functions
3:18
the computer a foot statement so, like, five feet 11 inches out of just pure inches 71 inches for example. And then computing the sign
3:28
so we want to show you're five pounds heavier or five pounds lighter than the average person of your height.
3:36
And I just want to reiterate this data is super sketchy and please don't take any of this as, like, accurate like look at real medical data and stuff
3:44
if you care about this. This is just a silly example and we just need some data that kind of sort of works. That's where that is.
3:50
We're going to run this application here to upload it all right, and we've already gone through building this application before
3:58
so we don't need to do it again, right. We basically did this with our interactive our fake mobile app or whatever.
4:06
Okay, so I'm just going to run this and we'll see what we get. So it's running. It found no data on the server, so it's going to load it.
4:13
It loaded 10000 entries. It then computed 41 averages by averaging that data and then it is uploading stuff so we'll give that a second.
4:25
We don't have any data on heart rate so I just said, well, the rate is 80. I don't even know if that's good or not
4:33
and it probably varies from male to female but it's 80. It doesn't really mean anything. We just need a number there. All that data is uploaded.
4:37
If we go over here and we go back to our data tables we should have data in our averages table. Here you go! We have a bunch of stuff on males
4:48
a bunch of stuff on females and their heights and then their weights and so on. Again, super sketchy data but here it is. So for the grand finale
4:56
let's run this and we'll see over here in this compare, it's going to go and do a filter for this height, this gender, and so on. You get an average.
5:09
It's going to take your latest measurement and it is going to... Here's your latest measurement.
5:15
And it's going to set the average as far as it's concerned average weight, and it's going to compute your weight and the change relative to the average
5:22
and it'll put a plus or minus and then the value. So let's run that see what we get. All right, let's compare. Compare me. Alright.
5:30
The average person my size, their weight is 201.9. Their heart rate, surprise, is 80 beats per minute. I weigh, according to my last measurement, 181
5:40
which is 21 pounds less than average and my heart rate was 74, which is 6 beats per minute less than average. Again, contrived data, semi-contrived.
5:51
I did get it from somewhere but I don't know how representative it is. Anyway, here's our cool little compare ourself.
5:57
And we were able to use our API and some scripts to load up that data and to compute that data. And I think that's a really cool aspect of it as well.
6:05
This should be it for our UI. We've got home. We've got add. We've got compare. We've got our account. Now, we haven't the go_pro part
6:15
but that's going to be the e-commerce stuff. And then if we log out, finally we have this unauthenticated home page
6:22
and then you try to go anywhere, it just says login. Okay, that's it. The UI for our app is done.