Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- from pymongo import MongoClient
- import numpy as np
- from datetime import datetime
- from _tkinter import TclError
- def get_pushmina():
- values = list(client.pushmina.photoresistor.find({}))
- values = sorted(values, key=lambda x: x['datetime'])
- timestamps = [value['datetime'] for value in values]
- values = [value['value'] for value in values]
- new_values = []
- previous = 0
- for value in values:
- if value != "":
- new_values.append(int(value))
- previous = int(value)
- else:
- new_values.append(previous)
- return timestamps, new_values
- def correct_values(timestamps, values):
- new_values = []
- previous = 0
- for value in values:
- if value != "":
- new_values.append(int(value))
- previous = int(value)
- else:
- new_values.append(previous)
- return timestamps, new_values
- def get_others(label):
- values = []
- if label == "serebrennikov":
- values = list(client.serebrennikov.photoresistor.find({}))
- if label == "tsybulya":
- values = list(client.tsybulya.photoresistor.find({}))
- if label == "chernogor":
- values = list(client.chernogor.photoresistor.find({}))
- if label == "bykov":
- values = list(client.bykov.values.find({}))
- if label == "pushmina":
- values = list(client.pushmina.photoresistor.find({}))
- values = sorted(values, key=lambda x: x['datetime'])
- timestamps = [value['datetime'] for value in values]
- values = [value['value'] for value in values]
- return timestamps, values
- def sortByStartDate(dt, timestamps, values):
- sorted = np.c_[timestamps, values]
- result = np.array([])
- result.shape = (0, 2)
- for value in sorted:
- if value[0] >= dt:
- result = np.vstack((result, value))
- return result[:, 0], result[:, 1]
- def sortByStopDate(dt, timestamps, values):
- sorted = np.c_[timestamps, values]
- result = np.array([])
- result.shape = (0, 2)
- for value in sorted:
- if value[0] <= dt:
- result = np.vstack((result, value))
- return result[:, 0], result[:, 1]
- client = MongoClient("roboforge.ru", username="admin",
- password="pinboard123", authsource="admin",
- serverSelectionTimeoutMS=5000, socketTimeoutMS=2000)
- startDatetime = datetime(2021, 5, 27, 10, 30)
- stopDatetime = datetime(2021, 5, 27, 16, 30)
- # startDatetime = None
- # stopDatetime = None
- fig = plt.figure()
- databases = ["bykov", "chernogor", "pushmina", "serebrennikov", "tsybulya"]
- while True:
- try:
- for database in databases:
- timestamps, values = get_others(database)
- if database == "pushmina":
- timestamps, values = correct_values(timestamps, values)
- if startDatetime:
- timestamps, values = sortByStartDate(
- startDatetime, timestamps, values)
- if stopDatetime:
- timestamps, values = sortByStopDate(
- stopDatetime, timestamps, values)
- plt.plot(timestamps, values)
- fig.legend(databases)
- print(datetime.now())
- plt.draw()
- plt.pause(60)
- fig.clear()
- except TclError:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement