-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.py
More file actions
95 lines (73 loc) · 2.7 KB
/
demo.py
File metadata and controls
95 lines (73 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import time
import json
import pandas as pd
import math
from influxdb import InfluxDBClient
from influxdb import DataFrameClient
from datetime import datetime, timedelta
from pytz import timezone
import datetime######################## MAIN ########################
import pytz
import hashlib
import argparse
import configparser
import subprocess
import numpy as np
from datetime import datetime
from tabulate import tabulate
import os
import sys
import ast
from Influx_Dataframe_Client import Influx_Dataframe_Client
#To run this script clone the repo and use the command: python3 demo.py conf.ini
######################## MAIN ########################
def main():
# read arguments passed at .py file call
parser = argparse.ArgumentParser()
parser.add_argument("config", help="Need to specify config file, see example_server.ini")
args = parser.parse_args()
conf_file = args.config
tags_list = ["ap_name","building_number","floor","room"]
fields_list = ["AP_count","test_field"]
database='local_btu'
measurement='wifi_measurement'
#make a single json dictionary in the format that InfluxDBClient expects
json = {
'fields': {
'AP_count': 1.0,
'test_field': 1.0
},
'time': '2016-04-01 07:00:00+0000',
'tags': {
'floor': '1',
'building_number': '100',
'ap_name': 'ap135-100-103d-r177',
'room': '03d'
},
'measurement': 'wifi_data9'
}
#take in csv file
data = pd.read_csv('example.csv')
print(data)
# create client
test_client = Influx_Dataframe_Client(conf_file,'local_db_config')
#demo all ways to write data into database using client
test_client.write_csv('example.csv',tags_list,fields_list,measurement,database)
test_client.write_json(json,database)
test_client.write_dataframe(data,tags_list,fields_list,measurement,database)
fields_list = ['AP_count']
tags_list = ['building_number','floor']
values_list = ['100','1']
'''
query below is equal to:
SELECT * FROM "wifi_measurement" WHERE time > '2016-03-01 06:00:00' AND time < '2016-04-02 08:00:00' AND "building_number" = '100' AND "floor" = '1'
since there is no fields specified the * is added into the query
'''
query_result = test_client.specific_query(database,measurement,start_time='2016-03-01 06:00:00', end_time='2016-04-02 08:00:00',tags=tags_list,values=values_list)
#query below is equal to: Select * from MEASUREMENT_ARGUMENT using DATABASE_ARGUMENT
query_result2 = test_client.specific_query(database,measurement)
print(query_result)
print(query_result2)
return
if __name__ == "__main__":
main()