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

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 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%
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...
How do I create a choropleth map of the United States where there are two maps....
How do I create a choropleth map of the United States where there are two maps. One that shows the states and one that shows the counties, in Rstudio, from the beginning. When I hover a state or county the border should be highlighted and the name of the state/county displayed.   I need to do this so that I can display the COVID-19 data that I have.
How do I create a choropleth map of the United States where there are two maps....
How do I create a choropleth map of the United States where there are two maps. One that shows the states and one that shows the counties, in PYTHON, from the beginning. When I hover a state or county the border should be highlighted and the name of the state/county displayed. I would like to use Plotly and the covid-19 dataset that I have. It contains latitude and longitude coordinates for each state or county.
Hello I have a data set of stock price from previous year. I want to know...
Hello I have a data set of stock price from previous year. I want to know the probability of stock price to be more than a certain value after x days starting from where the dataset ends. Which way do i need to approach. I thought of logistic regression, if its correct what do i need to do to move forward. Thank you!
In python I have a linked list. I want to create one function that takes in...
In python I have a linked list. I want to create one function that takes in one parameter, head. In the function, cur = head and next_cur = head.next. I want to return head and next_cur, except at the end of the function they will return alternating values from head. For example, if the these are the values in the linked list: 2, 3, 5, 7, 11 after the function head should return: 2, 5, 11 and next_cur should return:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT