Black Lives Matter. Please consider donating to Black Girls Code today.

How many API calls in my code

Hi,

I would like to create x amount of plots, each including 5 data streams. Now, I’m wondering how many API calls/day this would require. Depending on that I would need to upgrade my Plotly plan. Below you find parts of my source code. Can somebody tell me how when exactly it performs an API call?


import tkinter as tk
from tkinter import filedialog
import pandas as pd
import os
from numpy import genfromtxt
from numpy import *
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt
import plotly.plotly as py
import plotly.graph_objs as go
import time
import plotly.tools as tls
from random import randint
from datetime import timedelta
tls.set_credentials_file(username='ABC', api_key='123')

stream_tokens = ['cuujaigvam', '27a6oqxj17', 'ojwbuztynt', 'j7uungxwxp', '8xhz5pzgyl']# tls.get_credentials_file()['stream_ids']
token_1 = stream_tokens[0]   # I'm getting my stream tokens from the end to ensure I'm not reusing tokens
token_2 = stream_tokens[1]   
token_3 = stream_tokens[2]
token_4 = stream_tokens[3]   
token_5 = stream_tokens[4]
stream_id1 = dict(token=token_1, maxpoints=96)
stream_id2 = dict(token=token_2, maxpoints=96)
stream_id3 = dict(token=token_3, maxpoints=96)
stream_id4 = dict(token=token_4, maxpoints=96)
stream_id5 = dict(token=token_5, maxpoints=96)

trace_1 = go.Scatter(
        x=[],
        y=[],
        stream=stream_id1,
        mode = 'lines+markers',
        name = 'Turbidity',
        connectgaps = False,
        marker = dict(
            size = 5,
            color = 'rgb(64, 97, 139)',
            line = dict(
                width = 1,
                color = 'rgb(64, 97, 139)' 
            )
        )
    )
trace_2 = go.Scatter(
        x=[],
        y=[],
        stream=stream_id2,
        mode = 'lines+markers',
        name = 'Battery',
        connectgaps = False,
        marker = dict(
            size = 5,
            color = 'rgb(117, 157, 74)',
            line = dict(
                width = 1,
                color = 'rgb(117, 157, 74)'
            )
        )
    )
trace_3 = go.Scatter(
        x=[],
        y=[],
        stream=stream_id3,
        mode = 'lines+markers',
        name = 'Conductivity',
        connectgaps = False,
        marker = dict(
            size = 5,
            color = 'rgb(130, 130, 132)',
            line = dict(
                width = 1,
                color = 'rgb(130, 130, 132)'
            )
        )
    )
trace_4 = go.Scatter(
        x=[],
        y=[],
        stream=stream_id4,
        mode = 'lines+markers',
        name = 'Depth',
        connectgaps = False,
        marker = dict(
            size = 5,
            color = 'rgb(204, 0, 0)',
            line = dict(
                width = 1,
                color = 'rgb(204, 0, 0)'
            )
        )
    )
trace_5 = go.Scatter(
        x=[],
        y=[],
        stream=stream_id5,
        mode = 'lines+markers',
        name = 'Temperature',
        connectgaps = False,
        marker = dict(
            size = 5,
            color = 'rgb(255, 128, 0)',
            line = dict(
                width = 1,
                color = 'rgb(255, 128, 0)'
            )
        )
    )
    
data = [trace_1, trace_2, trace_3, trace_4, trace_5]
layout = go.Layout(
        title='Station XYZ',
        xaxis = dict(title='Date and Time'),
        yaxis = dict(title='Value [unit]'))
fig = go.Figure(data=data, layout=layout)
plot_url = py.plot(fig, filename='turbidity', auto_open = False, fileopt = 'overwrite')

s_1 = py.Stream(stream_id=token_1)
s_2 = py.Stream(stream_id=token_2)
s_3 = py.Stream(stream_id=token_3)
s_4 = py.Stream(stream_id=token_4)
s_5 = py.Stream(stream_id=token_5)

time_start = round_time(datetime.now(), timedelta(seconds = 5), 'down')
time_plot = time_start

print("Plotting will start at " + date2str(time_start, '%Y/%m/%d %H:%M:%S'))
while time_start > datetime.now():
    time.sleep(10)

s_1.open()
s_1.write(dict(x=[], y=[]))
s_1.close()
s_2.open()
s_2.write(dict(x=[], y=[]))
s_2.close()
s_3.open()
s_3.write(dict(x=[], y=[]))
s_3.close()
s_4.open()
s_4.write(dict(x=[], y=[]))
s_4.close()
s_5.open()
s_5.write(dict(x=[], y=[]))
s_5.close()

i = 0
while True:    
    if time_plot > datetime.now():
        time.sleep(10)
    else:    
        s_1.open()
        s_2.open()
        s_3.open()
        s_4.open()
        s_5.open()
        
        filepath_input = 'C:\\Users\\Julian\\Desktop\\Telemetry Web App\\'
        filename_input_station1 = 'data_stream_01.csv'
        path_station1 = os.path.join(filepath_input,filename_input_station1)  
        time_station1, turb_station1, battery_station1, cond_station1, depth_station1, temp_station1,  = read_data(path_station1)
        
        s_1.write(dict(x=time_station1,y=turb_station1))
        s_2.write(dict(x=time_station1,y=battery_station1))    
        s_3.write(dict(x=time_station1,y=cond_station1))
        s_4.write(dict(x=time_station1,y=depth_station1))
        s_5.write(dict(x=time_station1,y=temp_station1))
        
        print("Updated plot at " + date2str(time_plot, '%Y/%m/%d %H:%M:%S'))
    
        i += 1
        time_plot += timedelta(seconds = 10)
        s_1.close()
        s_2.close()
        s_3.close()
        s_4.close()
        s_5.close()