-
Notifications
You must be signed in to change notification settings - Fork 1
/
argone.py
126 lines (118 loc) · 3.49 KB
/
argone.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# usage: python argo.py
# creates empty collections in the argo db called argoMeta and argo with schema validation enforcement and defined indexes
from pymongo import MongoClient
import sys
client = MongoClient('mongodb://database/argo')
db = client.argo
metacollection = 'argoneMeta'
datacollection = 'argone'
db[metacollection].drop()
db.create_collection(metacollection)
db[datacollection].drop()
db.create_collection(datacollection)
argoneMetaSchema = {
"bsonType": "object",
"required": ["_id", "data_type", "data_info", "date_updated_argovis", "source", "levels"],
"properties":{
"_id": {
"bsonType": "string"
},
"data_type": {
"bsonType": "string"
},
"data_info": {
"bsonType": "array",
"items": {
"bsonType": "array",
"items": {
"bsonType": ["string", "array"]
}
}
},
"date_updated_argovis": {
"bsonType": "date"
},
"source": {
"bsonType": "array",
"items": {
"bsonType": "object",
"properties": {
"doi": {
"bsonType": "string",
}
}
}
},
"levels": {
"bsonType": "array",
"items": {
"bsonType": ["int", "string", "double"]
}
},
"level_units": {
"bsonType": "string"
}
}
}
argoneSchema = {
"bsonType": "object",
"required": ["_id","metadata","geolocation","geolocation_forecast","data"],
"properties": {
"_id": {
"bsonType": "string"
},
"metadata": {
"bsonType": "array",
"items": {
"bsonType": "string"
}
},
"geolocation": {
"bsonType": "object",
"required": ["type", "coordinates"],
"properties": {
"type":{
"enum": ["Point"]
},
"coordinates":{
"bsonType": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"bsonType": ["double", "int"]
}
}
}
},
"geolocation_forecast": {
"bsonType": "object",
"required": ["type", "coordinates"],
"properties": {
"type":{
"enum": ["Point"]
},
"coordinates":{
"bsonType": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"bsonType": ["double", "int"]
}
}
}
},
"data": {
"bsonType": "array",
"items": {
"bsonType": "array",
"items": {
"bsonType": ["double", "int", "string", "null"]
}
}
}
}
}
db.command('collMod',metacollection, validator={"$jsonSchema": argoneMetaSchema}, validationLevel='strict')
db.command('collMod',datacollection, validator={"$jsonSchema": argoneSchema}, validationLevel='strict')
db[datacollection].create_index([("geolocation", "2dsphere")])
db[datacollection].create_index([("geolocation_forecast", "2dsphere")])