Question

In: Computer Science

I want to create a d3 map visualization with timeseries data which pulls data from a...

I want to create a d3 map visualization with timeseries data which pulls data from a mysql table. The map will change data every second which would jump from data which contain x datetime to data which contain x+1 datetime (for example January 1 data to January 2). How can I do this? I already know how to set up a Flask API using Python which connects my visual to the database. I just need the SQL Query to change every second so that the plots in the map will change every second as well. Thanks!

Solutions

Expert Solution

So to get the datetime data from the database you first need to understand how the data is stored in database.

If the data is stored in DATETIME FORMAT so it should be like this YYYY-MM-DD HH:MI:SS.

If the data is stored in DATE Format it should be like this YYYY-MM-DD.

Since you asked for the data day wise, I am assuming it is stored in DATE format so to get the data you can make a function of python to get data and you could use the python time library to update the visual every second and python datetime library to iterate over dates.

Let me show you the query with an example to get data from the db every second.

import datetime

import mysql.connector

import time

# Connectivity to the database

db = mysql.connector.connect(

    host = 'localhost'

    user='user123'

    passwd = 'passwd123'

    database = 'mydb'

)

mycursor = db.cursor()

# Specify your begining date

startdate = datetime.date(2019,1,2)

# Next value for the while loop

next = startdate + datetime.date.resolution

# Specify your end date

enddate = datetime.date(2099,12,30)

while next <= enddate:

    currentdate = startdate

    # Executing the query

    mycursor.execute("""

        SELECT * FROM table WHERE date = %s

        """, (currentdate))

    

    # These are the values for the specific date

    value = mycursor.fetchone()

    print(value)

    # Changing the date to the next date

    currentdate = next

    next = currentdate + datetime.date.resolution

    time.sleep(1)

   

So Let me explain the code a bit, to iterate over the dates we have used the DATETIME module of python.

You need to specify the starting and ending date of your dataset and then it'll do the rest. The 'values' variable gets the data you need. You just need to specify the db, the credentials, start time, end time and query. The TIME module is used to get the data every one second. Just implement the logic in your code and it will be working like a charm.

THANK YOU.


Related Solutions

Using HTML/Javascript (if needed) I want to create a table for a website that pulls data...
Using HTML/Javascript (if needed) I want to create a table for a website that pulls data from another website where the data is being updated on. Example: https://investors.coca-colacompany.com/stock-information/historical-data I cannot just put in the numbers to a table as they will be getting updated daily. So it needs to link the the website elements. DATE OPEN HIGH LOW CLOSE VWAP VOLUME % CHG CHANGE TRADE VAL TOTAL TRADES 2020-10-13 -- -- -- 51.09 -- -- 0.00% -- -- -- 2020-10-12...
Create a Weather API.(ANY LANUGUAGE). " that pulls out information from web and stores the data...
Create a Weather API.(ANY LANUGUAGE). " that pulls out information from web and stores the data in back end. in which users can enter location: city or zip code to get the weather of that city or state. weather info should be in degree farenhit and centigrade. it should show the images as you see in you phone for weather and speed, etc. and it should change picture according to weather. for example, rain, cloudy, sunny, night, thunder. SHOW THE...
Develop a BST data type that supports: insert, search, remove and then Create a visualization for...
Develop a BST data type that supports: insert, search, remove and then Create a visualization for the BST data type you developed
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input...
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input system for a university student, where they put the season and year of when they started their uni course. For example the system will ask "What year did you start your degree?", the user will input "Autumn/2022" as a string. Now from a string format as shown, it should take that user input and calculate for example +2 or +3 years to the date....
Implement a method that does the following: (a) Create a Map data structure to hold the...
Implement a method that does the following: (a) Create a Map data structure to hold the associations between player name (key) and team affiliation (value) (b) Add at least 5 mappings to the map (c) Print out the current roster of mappings (d) Assuming some time has passed, change some of the mappings to simulate the players changing their affiliations (e) Again, print out the current roster of mappings 3. Implement a main method that calls the above methods, demonstrating...
I want to create an app which a user can talk to and get emotional feedback...
I want to create an app which a user can talk to and get emotional feedback in a form of a conversation. So, a user can talk about how stressful their day was, and my app should reply accordingly so that the user feels better. I want to know what methods(pyschologically) I can apply on my bot so that the user feels satisfied. In short, is there any psychological therapy term which deals with such conversations? Also, what all illnesses...
i want to create a weather api. which is pullling out information of all the cities(for...
i want to create a weather api. which is pullling out information of all the cities(for the whole world)  using their names or by their zipcode. and it should change the background image as the temperature is, cold, or hot, or mild etc. i need in help in making this weather api and also it can be in any language. please help me out
I want to calculate a sample size before I collect CATEGORICAL data. If I want no...
I want to calculate a sample size before I collect CATEGORICAL data. If I want no more than 3% margin of error find the sample size I would need for the following intervals. a8) 85% a9) 90% a10) 95% Repeat a8 - 10, but this time with a 5% margin of error a11) 85% a12) 90% a13) 95%
I want to create a seating chart that I can assign an 'X' to if a...
I want to create a seating chart that I can assign an 'X' to if a seat is purchased. I want to use a numpy array, but am having trouble figuring out how to write it the way I want it. I want it 4 X 15, but with string values instead of all the same value or a range. i would like this. can I do it with numpy? also I want the columns lined up when i do...
A magician wants to do the trick in which he pulls a tablecloth from a table,...
A magician wants to do the trick in which he pulls a tablecloth from a table, leaving the items on the table behind, unmoved. It turns out that this isn't magic at all, but simple physics. Let's assume that the tablecloth has to be slide horizontally a distance of 50 cm before it has slipped out from underneath a dish that lays on top of it. If the tablecloth's mass is 10 grams and the dish has a mass of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT