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

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 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%
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.
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...
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:...
PLEASE Create a perceptual map using the following data: After researching the demographic and competitive profile...
PLEASE Create a perceptual map using the following data: After researching the demographic and competitive profile of several markets, they decided Dallas, Texas, would be the best place to start their business. In examining the markets, they were looking for a town that would best fit their target market of singles and families in the age range of 18 to 50. The population of Dallas was almost 5.5 million people, of which about 50 percent were between the ages of...
can you please create the code program in PYTHON for me. i want to create array...
can you please create the code program in PYTHON for me. i want to create array matrix Nx1 (N is multiple of 4 and start from 16), and matrix has the value of elements like this: if N = 16, matrix is [ 4 4 4 4 -4 -4 -4 -4 4 4 4 4 -4 -4 -4 -4] if N = 64, matrix is [8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8...
I want to create an image compression program with matlab use PCA. I have the code...
I want to create an image compression program with matlab use PCA. I have the code listed below. But this code is fail, the image is colorless, but still gray. Can you help me to fix my code. clc clear all picture = im2double(imread('picture1.jpg')); Red = picture(:,:,1); premean = mean(Red(:)); premax = max(Red(:)); premin = min(Red(:)); x = size(Red,1); y = size(Red,2); Z = ones(x,y)*premean; A = (Red - Z)*(1/premax - premin); B = cov(A); [veceig,eig,C] = pcacov(B); NewRed =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT