Code Monkey home page Code Monkey logo

Comments (8)

tobinatore avatar tobinatore commented on June 16, 2024

Thank you! So basically, the Date model represents a single day in the timeseries of infections for a country. As you might've seen, it stores the date, number of confirmed infections, deaths and recoveries on that given day, as well as the country the numbers are for. This data is then used when a user selects a country in the table or the dropdown to populate the chart which shows the spread of the disease.

The Live model on the other hand contains a (more or less) live overview for every country and is used to populate the table on the left side. It's updated hourly.

The reasoning behind creating the Live model was that I did not want to send a request to my sources to fetch and process the data every time a user visits my site. This would generate a lot of traffic, whereas right now there's one request an hour. The same thing applies to the Date model. The file containing the timeseries JHU publishes is pretty large and it's not practicable to process the whole file whenever someone wants to see the statistics for a country. So I requested the whole file when I set the application up, stored every date for every country in a Date object and saved those to a PostgreSQL database. Now I just need to (automatically) update that database once a day to include the newest numbers and can query it easily whenever a user needs something.

I hope that explanation cleared everything up. If you have more questions ask away!

from covid19-tracker.

j0hnk1m avatar j0hnk1m commented on June 16, 2024

Thank you for the response! Sorry I'm new to django also, but how do you set it up so that there's only one request an hour? And how did you deploy your app?

from covid19-tracker.

tobinatore avatar tobinatore commented on June 16, 2024

how do you set it up so that there's only one request an hour?

I chose the rather simple approach of saving the time when the data should be updated in the Live model. When the entries for the table get generated, I populate the "time" field with the current time plus an hour. Now when a user visits the site, the application checks whether the time of the visit is after the scheduled update time or not. If that's the case, the records get updated, if not nothing happens.
Like I said, this is a pretty simple approach. You could also create a cron job to update the database and schedule it to run hourly.

And how did you deploy your app?

I used DigitalOcean for the hosting. They have some nice guides for setting up a droplet to use Django with a PostgreSQL database and Gunicorn/Nginx. You can find the one I used here. But it basically boils down to:

  1. Setting up a Github repository for the project
    So you can easily clone the project wherever you need it.
  2. Creating a droplet on DigitalOcean
    The cheapest 5$/month Ubuntu one will do (unless you're expecting high loads).
  3. Following the guide I linked
    Which is basically configuring your server, installing dependencies, cloning your project, setting up config files for gunicorn and nginx and testing whether everything worked.
  4. Getting a domain (optional but recommended)
    As far as I know you can actually access the application via the droplet IP, but it's easier for the general public to remember a domain and not some arbitrary numbers. For this step I used one of the free name.com domains from the Github student developer pack.
  5. Setting up the domain to point to your droplets IP
    What I did was create an A record, which redirects covid19app.live to my droplets IP and a CNAME record which acts as an alias and maps www.covid19app.live to the A record. This makes sure that you get to the right site no matter if you're using "www." or not.
  6. Updating the nameservers at the registrar
    Lastly I headed over to name.com and changed the default name.com nameservers to the ones provided by DigitalOcean. This change took a while to take effect and until then the site was not reachable via the domain, just as a heads up.

All in all it's actually really simple and pretty cheap to run such a web app (it's actually the first one I deployed). The total cost (if I didn't have the DigitalOcean credits and the free domain) would be 21.99$/year for the domain and 60$/year for the droplet or ~6.83$/month for everything.

from covid19-tracker.

j0hnk1m avatar j0hnk1m commented on June 16, 2024

Nice, thanks for all the info!

from covid19-tracker.

j0hnk1m avatar j0hnk1m commented on June 16, 2024

What javascript plugin did you use for the map? It looks awesome.

from covid19-tracker.

tobinatore avatar tobinatore commented on June 16, 2024

I used a jQuery plugin called jVectorMap. You can find it here.

from covid19-tracker.

j0hnk1m avatar j0hnk1m commented on June 16, 2024

I tried using it, but when I include the tutorial code, all I get is a blank white spot where the map should be. Did you ever have this error?

from covid19-tracker.

tobinatore avatar tobinatore commented on June 16, 2024

To be honest, I don't remember. Have you downloaded one of the world maps from here? Without one of these it won't render anything if I recall correctly.

from covid19-tracker.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.