This repository was archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
72 lines (61 loc) · 1.91 KB
/
Copy pathapp.py
File metadata and controls
72 lines (61 loc) · 1.91 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
__author__ = "Daniel Sosa"
__date__ = "April 14, 2022"
from datetime import datetime
import calendar
import random
from flask import Flask, jsonify
from flask_restful import Api, Resource
app = Flask(__name__)
api = Api(app)
class HelloWorld(Resource):
def get(self):
return {"data":"Hello World"}
api.add_resource(HelloWorld, "/helloworld")
class Home(Resource):
def get(self):
currentMonth = datetime.now().month
month = calendar.month_name[currentMonth]
summary = "Energy usage looks good"
moneysaved = random.randint(-200,200)
powersaved = moneysaved * 27
savings = "$"+str(moneysaved)+" : "+str(powersaved)+"KWH"
delta = random.randint(-15,20)
plugs = ["plug1","plug2","plug4"]
return {
'month':month,
'summary':summary,
'savings':savings,
'delta':delta,
'plugs':plugs
}
api.add_resource(Home, "/home")
class DashboardMonth(Resource):
def get(self):
print("Providing Month Data\n")
points = []
samples = datetime.now().day #Samples = day of month
for day in range(samples):
pwr = random.randint(400,800)
points.append(day)
points.append(pwr)
print(points)
return {
'points':points
}
api.add_resource(DashboardMonth, "/dashboard/month")
class DashboardDay(Resource):
def get(self):
print("Providing Day Data\n")
points = []
samples = datetime.now().hour #Samples = current hour in 24 hour format (noon = 12, 5 pm = 17)
for day in range(samples):
pwr = random.randint(0,25)
points.append(day)
points.append(pwr)
print(points)
return {
'points':points
}
api.add_resource(DashboardDay, "/dashboard/day")
if __name__ == "__main__":
app.run(debug=True)