This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Data Write Method 1 | |
IC.write_data(["MSFT_2021-11-07_Line_Protocol,stock=MSFT Open=62.79,High=63.84,Low=62.13"]) | |
# Data Write Method 2 | |
IC.write_data( | |
[ | |
Point('MSFT_2021-11-07_Point_Class') | |
.tag("stock","MSFT") | |
.field("Open",65) | |
.field("High",63.38) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
MSFT_file = open('Data/MSFT.csv') | |
csvreader = csv.reader(MSFT_file) | |
header = next(csvreader) | |
rows = [] | |
for row in csvreader: | |
date,open,high,low = row[0],row[1],row[2],row[3] | |
line_protocol_string = '' | |
line_protocol_string+=f'MSFT_{date},' | |
line_protocol_string+=f'stock=MSFT ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Return the High Value for MSFT stock for since 1st October,2021 | |
''' | |
query1 = 'from(bucket: "TestBucket")\ | |
|> range(start: 1633124983)\ | |
|> filter(fn: (r) => r._field == "High")\ | |
|> filter(fn: (r) => r.stock == "MSFT")' | |
IC.query_data(query1) | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from influxdb_client.client.write_api import SYNCHRONOUS, ASYNCHRONOUS | |
def write_data(self,data,write_option=SYNCHRONOUS): | |
write_api = self._client.write_api(write_option) | |
write_api.write(self._bucket, self._org , data,write_precision='s') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def query_data(self,query): | |
query_api = self._client.query_api() | |
result = query_api.query(org=self._org, query=query) | |
results = [] | |
for table in result: | |
for record in table.records: | |
results.append((record.get_value(), record.get_field())) | |
print(results) | |
return results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def delete_data(self,measurement): | |
delete_api = self._client.delete_api() | |
start = "1970-01-01T00:00:00Z" | |
stop = "2021-10-30T00:00:00Z" | |
delete_api.delete(start, stop, f'_measurement="{measurement}"', bucket=self._bucket, org=self._org) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Delete Data Point with measurement = 2021-10-29 | |
''' | |
IC.delete_data("MSFT_2021-10-29") | |
''' | |
Return the High Value for the MSFT stock on 2021-10-29 | |
''' | |
query2 = 'from(bucket: "TestBucket")\ | |
|> range(start: 1633124983)\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x,y = np.meshgrid(np.linspace(0, 50, 1000),np.linspace(0, 50, 1000)) | |
plt.imshow( | |
( | |
(x>=0)&(x<=10)&(y>=2)&(y<=15-x)&(y>=12-x)&(y<=10) | |
).astype(int) , | |
extent=(0,50,0,50), | |
origin="lower", | |
cmap="Reds", | |
alpha = 0.3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = np.linspace(0, 50, 1000) | |
y = np.linspace(0, 50, 1000) | |
''' | |
Draw Vertical Line | |
''' | |
plt.axvline(10, color='b', label=r'X <=10') | |
plt.axvline(0, color='b', label=r'X >=0') | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
anime_list = pd.read_csv('anime.csv') | |
print(anime_list.head(5)) |