# array of index, this test code use 2048 points data, # so The index is repeated every 2048 # ex) 0, 1, 2, 3....2047, 0, 1, 2, 3.......2047, 0.... index = 0 st = [] # The array of timestamps which start to inserting data en = [] # The array of timestamps which end to inserting data Test_time = [] # The array of test time try: for length in range(Loop): if index % length_Hdata == 0: #If the index is larger than the data length(2048), it is changed back to 0. index = 0 st.append(get_float_time_stamp()) session.insert_record("root.turbine2.bently3500", length, measurements_list_, data_type_list_, values_list_[index]) en.append(get_float_time_stamp()) # Test_time.append(en[i]-st[i]) index += 1 finally: All_Test_time = en[-1] - st[0] print("Test_time: " + str(All_Test_time)) Writing_frequency = (Sensor * Loop) / All_Test_time print("Writing frequency: " + str(np.around(Writing_frequency, 2))) # close session connection. session.close() print("All executions done!!")
# # with open('nor11.dat') as file: # data = file.read().splitlines() # floats=[] # for elem in data: # try: # floats.append(float(elem)) # except ValueError: # pass data_types_ = [TSDataType.DOUBLE] measurements_ = ["s1"] # for time in range(len(floats)): # values = [floats[time]] # session.insert_record("root.testdat", time, measurements_, data_types_, values) floats = value_list[0] for time in range(len(floats)): values = [floats[time]] session.insert_record("root.testdat", time, measurements_, data_types_, values) # insert multiple records into database measurements_list_ = [["s1"], ["s2"]] values_list_ = [[float(data[0])], [floats[1]]] data_type_list_ = [data_types_, data_types_] device_ids_ = ["root.testdat", "root.testdat"] session.insert_records(device_ids_, [4, 5], measurements_list_, data_type_list_, values_list_)
# returns the elapsed milliseconds since the start of the program def millis(): dt = datetime.now() - start_time ms = (dt.days * 24 * 60 * 60 + dt.seconds) * 1000 + dt.microseconds / 1000.0 return ms milliseconds = 0 time = 0 start_time = datetime.now() try: while milliseconds < (3600 * 1000): values = [] temperature = 20.0 temperature += random.uniform(-1, 1) values.append(np.around(temperature, 4)) milliseconds = int(millis()) session.insert_record("root.one_h", milliseconds, measurements_, data_types_, values) time += 1 sleep(0.00048828125) finally: # close session connection. print(time) session.close() print("All executions done!!")
# setting multiple time series once. ts_path_lst_ = ["root.sg_test_01.d_01.s_04", "root.sg_test_01.d_01.s_05", "root.sg_test_01.d_01.s_06", "root.sg_test_01.d_01.s_07", "root.sg_test_01.d_01.s_08", "root.sg_test_01.d_01.s_09"] data_type_lst_ = [TSDataType.FLOAT, TSDataType.DOUBLE, TSDataType.TEXT, TSDataType.FLOAT, TSDataType.DOUBLE, TSDataType.TEXT] encoding_lst_ = [TSEncoding.PLAIN for _ in range(len(data_type_lst_))] compressor_lst_ = [Compressor.SNAPPY for _ in range(len(data_type_lst_))] session.create_multi_time_series(ts_path_lst_, data_type_lst_, encoding_lst_, compressor_lst_) # delete time series session.delete_time_series(["root.sg_test_01.d_01.s_07", "root.sg_test_01.d_01.s_08", "root.sg_test_01.d_01.s_09"]) # insert one record into the database. measurements_ = ["s_01", "s_02", "s_03", "s_04", "s_05", "s_06"] values_ = [False, 10, 11, 1.1, 10011.1, "test_record"] data_types_ = [TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64, TSDataType.FLOAT, TSDataType.DOUBLE, TSDataType.TEXT] session.insert_record("root.sg_test_01.d_01", 1, measurements_, data_types_, values_) # insert multiple records into database measurements_list_ = [["s_01", "s_02", "s_03", "s_04", "s_05", "s_06"], ["s_01", "s_02", "s_03", "s_04", "s_05", "s_06"]] values_list_ = [[False, 22, 33, 4.4, 55.1, "test_records01"], [True, 77, 88, 1.25, 8.125, "test_records02"]] data_type_list_ = [data_types_, data_types_] device_ids_ = ["root.sg_test_01.d_01", "root.sg_test_01.d_01"] session.insert_records(device_ids_, [2, 3], measurements_list_, data_type_list_, values_list_) # close session connection. session.close() print("All executions done!!")