seeds.py (13260B)
1 import pymongo 2 import datetime 3 4 client = pymongo.MongoClient('mongodb://localhost:27017/simple_resource_management_software') 5 db = client.get_database('simple_resource_management_software') 6 7 # Create collections 8 user_collection = db.get_collection('user_collection') 9 time_collection = db.get_collection('time_collection') 10 fleet_collection = db.get_collection('fleet_collection') 11 agreements_collection = db.get_collection('agreements_collection') 12 projects_collection = db.get_collection('projects_collection') 13 permissions_collection = db.get_collection('permissions_collection') 14 15 # Clean previous seeding 16 x = user_collection.delete_many({}) 17 x = time_collection.delete_many({}) 18 x = fleet_collection.delete_many({}) 19 x = agreements_collection.delete_many({}) 20 x = projects_collection.delete_many({}) 21 x = permissions_collection.delete_many({}) 22 23 # Database collections/documents 24 # Example create user via User constructor(all fields required) 25 #u2 = User(fname='hiccup',mname='',lname='crawford',email='hiccup@example.com',branch='Dillon', address='705 N Railroad Ave, Dillon MT, 59725',birthday='2022-11-17',role='Dog',phonenumber='3074380491') 26 # create password 27 #u2.set_password('hiccupmonster') 28 29 # User Documents 30 #document/json user_data, will have User.__init__() create userobj (routes.py) 31 #pw is 'password' 32 user1 = { 33 'fname': 'Nikolas', 34 'mname': 'M', 35 'lname': 'Mazur', 36 'username': 'nikolasmmazur', 37 'birthday': '1999-03-26', 38 'password_hash': 'pbkdf2:sha256:260000$DBIF9Dfq1OcsYwSk$37f5cc231ff2c97cc7a6b60f25c767380574f1c01cc17069da4f3e7e25ba3370', 39 'role': 'Web Developer', 40 'address': '275 DuPont Dr, Lander Wy 82520', 41 'branch': 'Lander', 42 'phonenumber': '3074380460', 43 'email': 'kolemazur@gmail.com', 44 'pay_period': 'hourly', 45 'pay_value': 15.12, 46 'is_active':False 47 } 48 49 #pw is 'password2' 50 user2 = { 51 'fname': 'Brennen', 52 'mname': 'T', 53 'lname': 'Mazur', 54 'username': 'brennentmazur', 55 'birthday': '1997-04-28', 56 'password_hash': 'pbkdf2:sha256:260000$ukazhSEG3m9xH2oL$5cc00ff3411f614720287c18f615d71578face70abc990ea5def89f520b0ac2c', 57 'role': 'Crew Lead', 58 'branch': 'Dillon', 59 'phonenumber': 3074380491, 60 'address': '705 N Railroad Ave, Dillon MT, 59725', 61 'email': 'brennen.mazur@gmail.com', 62 'pay_period': 'salaried', 63 'pay_value': 43000, 64 'is_active':True 65 } 66 67 user3 = { 68 'fname': 'Hiccup', 69 'mname': 'C', 70 'lname': 'Mazur', 71 'username': 'hiccupcmazur', 72 'birthday': '2022-09-14', 73 'password_hash': 'pbkdf2:sha256:260000$ukazhSEG3m9xH2oL$5cc00ff3411f614720287c18f615d71578face70abc990ea5def89f520b0ac2c', 74 'role': 'Crew', 75 'branch': 'Dillon', 76 'phonenumber': 3074380491, 77 'address': '705 N Railroad Ave, Dillon MT, 59725', 78 'email': 'hiccup.mazur@fake.com', 79 'pay_period': 'salaried', 80 'pay_value': 43000, 81 'is_active':True 82 } 83 84 # Time documents 85 time1 = { 86 'clock_in': [datetime.datetime.utcnow()], #System time Clock_out should be optional, but can clock_in? 87 'modified_by': ['nikolasmmazur'], #link to _id of user 88 'project': 'Project 2', #Probably link with projects foreign key 89 'clock_out': [datetime.datetime.utcnow()], #System time 90 'note': 'Changed due to clocking out early', 91 'per_diem': False, 92 # 'total_time': 93 } 94 95 time2 = { 96 'clock_in': [datetime.datetime.utcnow()], #System time Clock_out should be optional, but can clock_in? 97 'modified_by': ['nikolasmmazur','brennentmazur'], #link to _id of user 98 'project': 'Project 2', #Probably link with projects foreign key 99 'clock_out': [datetime.datetime.utcnow()], #System time 100 'note': 'Changed due to clocking out early', 101 'per_diem': False, 102 # 'total_time': 103 } 104 105 time3 = { 106 'clock_in': [datetime.datetime.utcnow()], 107 'modified_by': ['hiccupcmazur'], 108 'project': 'Project 5' 109 } 110 111 # Fleet documents 112 fleetpool = { 113 '_id':'Fleet Pool', 114 'available':['Vehicle1','Vehicle2','Vehicle3','Vehicle5','Vehicle6'], 115 'unavailable':[('Vehicle4','brennentmazur')] # Tuple for who checked vehicle lastOR set to 'REPAIRS' for obvious reasons 116 } 117 118 fleet1 = { 119 'date': datetime.datetime.today(), 120 'operator': 'brennentmazur', #forign key to userID 121 'start_mileage': 33, 122 'safety_checks': [True,True,True,True,True],#array for different safety checks 123 'additional_notes': 'Oil needs checked', 124 'vehicle': 'Vehicle4', #vehicleID 125 'incident_report': '' 126 } 127 128 fleet2 = { 129 'date': datetime.datetime.today(), 130 'operator': 'nikolasmmazur', #forign key to userID 131 'start_mileage': 33, 132 'end_mileage': 33, 133 # 'safety_checks': True, #array for different safety checks 134 'additional_notes': 'Tires need replaced', 135 'vehicle': 'The Small Truck', #vehicleID 136 'incident_report': 'I dunno what goes in incident reports.' 137 } 138 139 # Agreement documents 140 agreement1 = { 141 'agreement_name': 'Agreement 1', 142 'agency': ['USFS'], 143 'projects': [2,3,4], 144 'start_date': '2023-12-5', 145 'end_date': '2023-8-12', 146 #'bid_document': '/asset/document/agreements/New-Agreement.pdf', #Filepath to document 147 # 'budget': [{ 148 # 'labor':1259.40, 149 # 'travel':220.00, 150 # 'supplies':320.00, 151 # 'contact':420.00, 152 # 'equipment':620.00, 153 # 'other':20.00 154 # }], 155 # 'costs': [{ 156 # 'labor':159.40, 157 # 'travel':20.00, 158 # 'supplies':30.00, 159 # 'contact':40.00, 160 # 'equipment':60.00, 161 # 'other':2.00 162 # }] 163 } 164 165 agreement2 = { 166 'agreement_name': 'Agreement 2', 167 'agency': ['SMSP'], 168 'projects': [1,5], 169 'start_date': '2021-2-21', 170 'end_date': '2022-12-13', 171 #'bid_document': '/asset/document/agreements/Old-Agreement.pdf', #Filepath to document 172 # 'budget': [{ 173 # 'labor':259.40, 174 # 'travel':220.00, 175 # 'supplies':320.00, 176 # 'contact':420.69, 177 # 'equipment':20.00, 178 # 'other':20.00 179 # }], 180 # 'costs': [{ 181 # 'labor':159.40, 182 # 'travel':20.00, 183 # 'supplies':30.00, 184 # 'contact':40.00, 185 # 'equipment':60.00, 186 # 'other':2.00 187 # }] 188 } 189 190 # Projects documents 191 projects1 = { 192 '_id':1, 193 'project_name': 'Project 1', 194 'agreement': 2, 195 'budget': [{ 196 'labor':159.40, 197 'travel':420.00, 198 'supplies':20.00, 199 'contact':40.00, 200 'equipment':60.00, 201 'other':2.00 202 }], 203 'costs': [{ 204 'labor':159.40, 205 'travel':20.00, 206 'supplies':30.00, 207 'contact':40.00, 208 'equipment':60.00, 209 'other':2.00 210 }] 211 #'project_budget': [13.20, 0, 20, 300, 50, 0 212 # labor_budget: float | Indexed 0 213 # travel_budget: float | Indexed 1 214 # supplies_budget: float | Indexed 2 215 # contact_budget: float | Indexed 3 216 # equipment_budget: float | Indexed 4 217 # other: float | Indexed 5 218 #], 219 } 220 221 projects2 = { 222 '_id':2, 223 'project_name': 'Project 2', 224 'agreement': 1, 225 'budget': [{ 226 'labor':159.40, 227 'travel':820.00, 228 'supplies':1120.00, 229 'contact':42.00, 230 'equipment':75.00, 231 'other':12.00 232 }], 233 'costs': [{ 234 'labor':159.40, 235 'travel':20.00, 236 'supplies':30.00, 237 'contact':40.00, 238 'equipment':60.00, 239 'other':2.00 240 }] 241 #'project_budget': [13.20, 0, 20, 300, 50, 0 242 # labor_budget: float | Indexed 0 243 # travel_budget: float | Indexed 1 244 # supplies_budget: float | Indexed 2 245 # contact_budget: float | Indexed 3 246 # equipment_budget: float | Indexed 4 247 # other: float | Indexed 5 248 #], 249 } 250 251 projects3 = { 252 '_id':3, 253 'project_name': 'Project 3', 254 'agreement': 1, 255 'budget': [{ 256 'labor':459.40, 257 'travel':510.00, 258 'supplies':80.00, 259 'contact':94.20, 260 'equipment':9.00, 261 'other':27.00 262 }], 263 'costs': [{ 264 'labor':159.40, 265 'travel':20.00, 266 'supplies':30.00, 267 'contact':40.00, 268 'equipment':60.00, 269 'other':2.00 270 }] 271 #'project_budget': [13.20, 0, 20, 300, 50, 0 272 # labor_budget: float | Indexed 0 273 # travel_budget: float | Indexed 1 274 # supplies_budget: float | Indexed 2 275 # contact_budget: float | Indexed 3 276 # equipment_budget: float | Indexed 4 277 # other: float | Indexed 5 278 #], 279 } 280 projects4 = { 281 'project_name': 'Project 4', 282 '_id':4, 283 'agreement': 1, 284 'budget': [{ 285 'labor':258.40, 286 'travel':71.00, 287 'supplies':20.00, 288 'contact':4.00, 289 'equipment':66.00, 290 'other':59.00 291 }], 292 'costs': [{ 293 'labor':159.40, 294 'travel':20.00, 295 'supplies':30.00, 296 'contact':40.00, 297 'equipment':60.00, 298 'other':2.00 299 }] 300 #'project_budget': [13.20, 0, 20, 300, 50, 0 301 # labor_budget: float | Indexed 0 302 # travel_budget: float | Indexed 1 303 # supplies_budget: float | Indexed 2 304 # contact_budget: float | Indexed 3 305 # equipment_budget: float | Indexed 4 306 # other: float | Indexed 5 307 #], 308 } 309 projects5 = { 310 '_id':5, 311 'project_name': 'Project 5', 312 'agreement': 2, 313 'budget': [{ 314 'labor':1259.40, 315 'travel':220.00, 316 'supplies':320.00, 317 'contact':420.00, 318 'equipment':620.00, 319 'other':20.00 320 }], 321 'costs': [{ 322 'labor':159.40, 323 'travel':20.00, 324 'supplies':30.00, 325 'contact':40.00, 326 'equipment':60.00, 327 'other':2.00 328 }] 329 #'project_budget': [13.20, 0, 20, 300, 50, 0 330 # labor_budget: float | Indexed 0 331 # travel_budget: float | Indexed 1 332 # supplies_budget: float | Indexed 2 333 # contact_budget: float | Indexed 3 334 # equipment_budget: float | Indexed 4 335 # other: float | Indexed 5 336 #], 337 } 338 # Permissions documents (only needs array list of str for each 'service') 339 crew = { 340 '_id':1, 341 'label': 'Crew L1', 342 'dashboard': ['punchclock'], 343 'admin': [], 344 'base_pay_value':10.00 345 } 346 347 crew2 = { 348 '_id':2, 349 'label': 'Crew L2', 350 'dashboard': ['punchclock'], 351 'admin': [], 352 'base_pay_value':10.00 353 } 354 355 alead = { 356 '_id':3, 357 'label': 'Assistant Lead', 358 'dashboard': ['punchclock','fleet'], 359 'admin': [], 360 'base_pay_value':13.00 361 } 362 363 lead = { 364 '_id':4, 365 'label': 'Crew Lead', 366 'dashboard': ['punchclock','fleet','activeusers'], 367 'admin': [], 368 'base_pay_value':15.00 369 } 370 371 personelDirector = { 372 '_id':5, 373 'label': 'Personel Director', 374 'dashboard': ['punchclock','fleet','activeusers'], 375 'admin': ['agreements','reports','users','roles'], 376 'base_pay_value':10.00 377 } 378 379 developer = { 380 '_id':6, 381 'label': 'Web Developer', 382 'dashboard': ['punchclock','fleet','activeusers'], 383 'admin': ['agreements','reports','users','roles'], 384 'base_pay_value':32.00 385 } 386 387 ed = { 388 '_id':7, 389 'label': 'Executive Director', 390 'dashboard': ['punchclock','fleet','activeusers'], 391 'admin': ['agreements','reports','users','roles'], 392 'base_pay_value':10.00 393 } 394 395 manager = { 396 '_id':8, 397 'label': 'Project Manager', 398 'dashboard': ['punchclock','fleet','activeusers'], 399 'admin': ['agreements','reports','users','roles'], 400 'base_pay_value':25.00 401 } 402 403 accountant = { 404 '_id':9, 405 'label': 'Accountant', 406 'dashboard': ['punchclock','fleet','activeusers'], 407 'admin': ['agreements','reports','users'], 408 'base_pay_value':23.00 409 } 410 411 412 # Insert documents 413 user_collection.insert_many([user1, user2, user3]) 414 time_collection.insert_many([time1, time2,time3]) 415 fleet_collection.insert_many([fleetpool, fleet1, fleet2]) 416 agreements_collection.insert_many([agreement1, agreement2]) 417 projects_collection.insert_many([projects1, projects2, projects3, projects4, projects5]) 418 permissions_collection.insert_many([crew,crew2,alead,lead,personelDirecton,developer,ed,manager,accountant]) 419 420 # Print seeded data 421 for x in user_collection.find(): 422 print(x) 423 424 for x in time_collection.find(): 425 print(x) 426 427 for x in fleet_collection.find(): 428 print(x) 429 430 for x in agreements_collection.find(): 431 print(x) 432 433 for x in projects_collection.find(): 434 print(x) 435 436 for x in permissions_collection.find(): 437 print(x) 438 439 #print('making query on agreements and attempting to inject relavant projects') 440 #test_agreements = agreements_collection.find() 441 #fagreements=[] 442 #for agreement in test_agreements: 443 # for i in range(len(agreement['projects'])): 444 # print(agreement['projects'][i]) 445 # agreement['projects'][i] = projects_collection.find_one({'_id': agreement['projects'][i]}) 446 # # print(agreement['projects'][i]) 447 # #for a in agreement: 448 # #print(a) 449 # fagreements.append(agreement) 450 #for agree in fagreements: 451 # print(agree)