|
1 | 1 | import pymongo
|
2 | 2 |
|
3 |
| -from opensensor.db import get_open_sensor_db |
| 3 | +from opensensor.utils import get_open_sensor_db |
4 | 4 |
|
5 | 5 | # Script for creating the Time Series
|
6 | 6 |
|
7 | 7 | db = get_open_sensor_db()
|
8 |
| -# try: |
9 |
| -# db.create_collection( |
10 |
| -# "Temperature", |
11 |
| -# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
12 |
| -# ) |
13 |
| -# except pymongo.errors.CollectionInvalid: |
14 |
| -# print("Temperature collection Already exists, skipping ...") |
15 |
| -# |
16 |
| -# try: |
17 |
| -# db.create_collection( |
18 |
| -# "Humidity", |
19 |
| -# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
20 |
| -# ) |
21 |
| -# except pymongo.errors.CollectionInvalid: |
22 |
| -# print("Humidity collection Already exists, skipping ...") |
23 |
| -# |
24 |
| -# try: |
25 |
| -# db.create_collection( |
26 |
| -# "Pressure", |
27 |
| -# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
28 |
| -# ) |
29 |
| -# except pymongo.errors.CollectionInvalid: |
30 |
| -# print("Pressure collection Already exists, skipping ...") |
31 |
| -# |
32 |
| -# try: |
33 |
| -# db.create_collection( |
34 |
| -# "Lux", |
35 |
| -# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
36 |
| -# ) |
37 |
| -# except pymongo.errors.CollectionInvalid: |
38 |
| -# print("Lux collection Already exists, skipping ...") |
39 |
| -# |
40 |
| -# try: |
41 |
| -# db.create_collection( |
42 |
| -# "CO2", |
43 |
| -# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
44 |
| -# ) |
45 |
| -# except pymongo.errors.CollectionInvalid: |
46 |
| -# print("CO2 collection Already exists, skipping ...") |
47 |
| -# |
48 |
| -# try: |
49 |
| -# db.create_collection( |
50 |
| -# "Moisture", |
51 |
| -# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
52 |
| -# ) |
53 |
| -# except pymongo.errors.CollectionInvalid: |
54 |
| -# print("Moisture collection Already exists, skipping ...") |
55 |
| -# |
56 |
| -# try: |
57 |
| -# db.create_collection( |
58 |
| -# "pH", |
59 |
| -# timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
60 |
| -# ) |
61 |
| -# except pymongo.errors.CollectionInvalid: |
62 |
| -# print("pH collection Already exists, skipping ...") |
| 8 | +try: |
| 9 | + db.create_collection( |
| 10 | + "Temperature", |
| 11 | + timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 12 | + ) |
| 13 | +except pymongo.errors.CollectionInvalid: |
| 14 | + print("Temperature collection Already exists, skipping ...") |
| 15 | + |
| 16 | +try: |
| 17 | + db.create_collection( |
| 18 | + "Humidity", |
| 19 | + timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 20 | + ) |
| 21 | +except pymongo.errors.CollectionInvalid: |
| 22 | + print("Humidity collection Already exists, skipping ...") |
| 23 | + |
| 24 | +try: |
| 25 | + db.create_collection( |
| 26 | + "Pressure", |
| 27 | + timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 28 | + ) |
| 29 | +except pymongo.errors.CollectionInvalid: |
| 30 | + print("Pressure collection Already exists, skipping ...") |
63 | 31 |
|
64 | 32 | try:
|
65 | 33 | db.create_collection(
|
66 |
| - "FreeTier", |
| 34 | + "Lux", |
67 | 35 | timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"},
|
68 |
| - # expireAfterSeconds=8000000, |
69 | 36 | )
|
70 | 37 | except pymongo.errors.CollectionInvalid:
|
71 |
| - print("FreeTier collection Already exists, skipping ...") |
| 38 | + print("Lux collection Already exists, skipping ...") |
72 | 39 |
|
| 40 | +try: |
| 41 | + db.create_collection( |
| 42 | + "CO2", |
| 43 | + timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 44 | + ) |
| 45 | +except pymongo.errors.CollectionInvalid: |
| 46 | + print("CO2 collection Already exists, skipping ...") |
73 | 47 |
|
74 | 48 | try:
|
75 | 49 | db.create_collection(
|
76 |
| - "Migration", |
77 |
| - # timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
78 |
| - # expireAfterSeconds=8000000, |
| 50 | + "Moisture", |
| 51 | + timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
79 | 52 | )
|
80 |
| - db.Migration.create_index([("migration_name", 1)], unique=True) |
| 53 | +except pymongo.errors.CollectionInvalid: |
| 54 | + print("Moisture collection Already exists, skipping ...") |
81 | 55 |
|
| 56 | +try: |
| 57 | + db.create_collection( |
| 58 | + "pH", |
| 59 | + timeseries={"timeField": "timestamp", "metaField": "metadata", "granularity": "minutes"}, |
| 60 | + ) |
82 | 61 | except pymongo.errors.CollectionInvalid:
|
83 |
| - print("Migration collection Already exists, skipping ...") |
| 62 | + print("pH collection Already exists, skipping ...") |
0 commit comments