Exemple #1
0
def sample_sensor_data(sample_data_ammount):
    print("Creating sample 'Sensor' data...")
    data_created = 0
    pbar = tqdm(total=sample_data_ammount)
    while data_created < sample_data_ammount:
        random_track_id = random.choice(query.get_collection_docs('Tracks'))
        id = '{}{}'.format(random_track_id, random.randint(101,999)).translate({ord(char): None for char in "'[]'"})
        if query.check_data_existance('Sensors',id) == True:
            continue
        else:
            sensor_ref = query.db.collection('Sensors').document(id)
            sensor_ref.set(c_class.Timestamp(random_sensor_data()).to_dict())
            i = 1
            while i < 5:
                sensor_ref.update(c_class.Timestamp(random_sensor_data()).to_dict())
                pbar.update(+(1/4))
                i = i + 1
            data_created = data_created + 1
    print("\nSuccesfully sent all {} 'Sensor' data samples to the Database!".format(sample_data_ammount))
Exemple #2
0
def sample_investment_data(sample_data_ammount):
    print("Creating sample 'Investment' data...")
    data_created = 0
    pbar = tqdm(total=sample_data_ammount)
    while data_created < sample_data_ammount:
        random_sponsor_id = random.choice(query.get_collection_docs('Sponsors'))
        random_item_id = random.choice([random.choice(query.get_collection_docs('Tracks')), random.choice(query.get_collection_docs('Sensors')), random.randint(10001,99999)]) # add func to get control ids
        id = '{}{}'.format(random_sponsor_id, random_item_id)
        if query.check_data_existance('Investments',id) == True:
            continue
        else:
            investment_ref = query.db.collection('Investments').document(id)
            investment_ref.set(c_class.Timestamp(random_investment_data()).to_dict())
            i = 1
            while i < 5:
                investment_ref.update(c_class.Timestamp(random_investment_data()).to_dict())
                pbar.update(+(1/4))
                i = i + 1
            data_created = data_created + 1
    print("\nSuccesfully sent all {} 'Investment' data samples to the Database!".format(sample_data_ammount))
Exemple #3
0
def get_multiple_document_data_test(collection, document):
    doc_ref = db.collection(collection).document(document)
    docs = doc_ref.get()
    timestamp = c_class.Timestamp(docs.to_dict())
    for key, value in timestamp:
        investment = c_class.Investment(**value)
        print('Key = ', key)
        print('Value = ', value)
        print('Investment (class) data = ', investment)
        print('Investment.ammount = ', investment.ammount)
        print('Investment.hashtags =', investment.allocated_to)
        print('Investment.hashtags[i] =', investment.allocated_to[1])
        if 'fast' in investment.allocated_to:
            print("'term' is in 'hashtags'!")
        if not 'whom' in investment.allocated_to:
            print("'term' is NOT in 'hashtags'!")
        print("#---------------------------------------#")
                        print("Devices are cleared and ready for setup!\n Closing program...")
                        time.sleep(3)
                        exit(1)
                    else: ##IMPROVE THIS CSV FILE FORMATTING
                        csvfile_path = input("Please input the path for your CSV document:\n")
                        with open(csvfile_path, 'w', newline='') as csv_mode:
                            csv.writer(csv_mode).writerow(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))
                            smartband_row = csv.DictWriter(csv_mode, fieldnames=['Smartband Data'])
                            smartband_row.writeheader()
                            smartband_row.writerow({'Smartband Data': smartband_data})
                            sensor_row = csv.DictWriter(csv_mode, fieldnames=['Sensor Data'])
                            sensor_row.writeheader()
                            sensor_row.writerow({'Sensor Data': sensor_data})
        else: #edit 
            sensor_ref = query.db.collection('Sensors').document(id)
            sensor_ref.set(c_class.Timestamp(random_sensor_data()).to_dict())
            i = 1
            while i < 5:
                sensor_ref.update(c_class.Timestamp(random_sensor_data()).to_dict())
                pbar.update(+(1/4))
                i = i + 1
            data_created = data_created + 1
            arduino.write(b'b')
            print('Erasing wristband data...')
    except:
        continue
valid_data = (arduino_data[0:-2])
print('Parabens, voce percorreu {} metros na ultima trilha!'.format(valid_data[2]))
print(valid_data)
print('SensorID: {}, RegionID: {}, Sensor Position: {}, Avg. Attempt: {}, State: {}, Connections: {}'.format(
    valid_data[0],valid_data[1],valid_data[2],valid_data[3],valid_data[4],valid_data[5]))