forked from nextcolony1/nc_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix_data.py
651 lines (567 loc) · 29.1 KB
/
fix_data.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
import json
from datetime import timedelta, datetime
from beem.block import Block
from beem.amount import Amount
import requests
import time
import requests
import hashlib
import ast
import string
import base36
import random
import websocket
import sys
from random import randint
from utils.ncutils import checkifuser, findfreeplanet, shipdata, connectdb, get_shipdata,get_planetdata,get_distance,create_planet
from utils.ncutils import find_starterplanet_coords, generateUid, uid_from_block, write_spacedb, get_ship_data, get_item_data, get_planet_data, update_transaction_status, update_transfer_status
from utils.ncutils import get_custom_json_id, get_transfer_id, get_mission_data
from commands import move_ship, explorespace, transport_resources, offload_deploy, offload_return, get_resource_levels, build_ship, enhance
from commands import upgrade, activate, adduser, buy, explore, finish_building, finish_skill, gift_item, update_ranking, gift_planet, deploy_ships, rename_planet
from commands import update_shop, attack, battle_return, cancel, support, enable, charge, finish_charging, offload_deploy_mission, siege
from commands import break_siege, fly_home_mission, offload_return_mission, issue
# get the productivity data from the SQL DB
# Connect to the database
def fix_data(time_now, parameter, test_mode=False):
# get all open transactions from the database
# Connect to the database
start_time = time.time()
apply_fix1 = False
apply_fix2 = False
apply_fix3 = False
apply_fix4 = False
apply_fix5 = False
apply_fix6 = False
apply_fix7 = False
apply_fix8 = False
apply_fix9 = False
connection = connectdb()
table = connection["status"]
status = table.find_one(id=1)
last_data_fix_date = status["last_data_fix_date"]
if last_data_fix_date is None:
last_data_fix_date = datetime(2019, 1, 1, 0, 0, 0)
if time_now > datetime(2019, 7, 17, 9, 30, 0) and last_data_fix_date < datetime(2019, 7, 17, 9, 30, 0):
apply_fix1 = True
elif time_now > datetime(2019, 7, 17, 20, 0, 0) and last_data_fix_date < datetime(2019, 7, 17, 20, 0, 0):
apply_fix2 = True
elif time_now > datetime(2019, 7, 22, 9, 0, 0) and last_data_fix_date < datetime(2019, 7, 22, 9, 0, 0):
apply_fix3 = True
elif time_now > datetime(2019, 7, 22, 9, 35, 0) and last_data_fix_date < datetime(2019, 7, 22, 9, 35, 0):
apply_fix4 = True
elif time_now > datetime(2019, 8, 22, 14, 20, 0) and last_data_fix_date < datetime(2019, 8, 22, 14, 20, 0):
apply_fix5 = True
elif time_now > datetime(2019, 9, 4, 7, 0, 0) and last_data_fix_date < datetime(2019, 9, 4, 7, 0, 0):
apply_fix6 = True
elif time_now > datetime(2019, 10, 10, 7, 0, 0) and last_data_fix_date < datetime(2019, 10, 10, 7, 0, 0):
apply_fix7 = True
elif time_now > datetime(2019, 11, 6, 20, 30, 0) and last_data_fix_date < datetime(2019, 11, 6, 20, 30, 0):
apply_fix8 = True
elif time_now > datetime(2019, 11, 10, 14, 40, 0) and last_data_fix_date < datetime(2019, 11, 10, 14, 40, 0):
apply_fix9 = True
if test_mode:
#apply_fix1 = True
#apply_fix2 = True
#apply_fix3 = True
#apply_fix4 = True
#apply_fix6 = True
#apply_fix7 = True
#apply_fix8 = True
apply_fix9 = True
elif apply_fix1 or apply_fix2 or apply_fix3 or apply_fix4 or apply_fix5 or apply_fix6 or apply_fix7 or apply_fix8 or apply_fix9:
table = connection["status"]
table.update({"last_data_fix_date": time_now}, ["id"])
if apply_fix1:
print("Apply fix1")
table = connection["ships"]
ships = []
for ship in table.find(mission_id={'not': None}):
ships.append(ship["id"])
print("%d ships found" % len(ships))
cnt = 0
for shipid in ships:
cnt += 1
if cnt % 1000 == 0:
print("%d/%d ships processed" % (cnt, len(ships)))
table = connection["ships"]
ship = table.find_one(id=shipid)
if ship is None:
continue
if ship["mission_busy_until"] > time_now:
continue
mission_id = ship["mission_id"]
table = connection["missions"]
mission = table.find_one(mission_id=mission_id)
if mission is None:
continue
if ship["user"] != mission["user"]:
continue
if ship["cords_hor"] != mission["cords_hor_dest"]:
continue
if ship["cords_ver"] != mission["cords_ver_dest"]:
continue
table = connection["planets"]
planet = table.find_one(cords_hor=ship["cords_hor"], cords_ver=ship["cords_ver"])
if planet is None:
continue
if planet["user"] == ship["user"]:
continue
vops_waiting = False
table = connection["virtualops"]
for vops in table.find(mission_id=mission_id):
if vops["tr_status"] == 0:
vops_waiting = True
if vops_waiting:
continue
#if mission["busy_until_return"] is None:
# continue
if mission["busy_until_return"] is not None and mission["busy_until_return"] > time_now:
continue
if mission["mission_type"] in ["support"]:
continue
print(mission["mission_type"])
table = connection['ships']
print({"id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"])})
if not test_mode:
table.update({"id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"])},['id'])
if apply_fix2:
print("Apply fix1")
table = connection["ships"]
ships = []
for ship in table.find(mission_id={'not': None}):
ships.append(ship["id"])
print("%d ships found" % len(ships))
cnt = 0
for shipid in ships:
cnt += 1
if cnt % 1000 == 0:
print("%d/%d ships processed" % (cnt, len(ships)))
table = connection["ships"]
ship = table.find_one(id=shipid)
if ship is None:
continue
if ship["mission_busy_until"] > time_now:
continue
mission_id = ship["mission_id"]
table = connection["missions"]
mission = table.find_one(mission_id=mission_id)
if mission is None:
continue
if ship["user"] != mission["user"]:
continue
if ship["cords_hor"] != mission["cords_hor_dest"]:
continue
if ship["cords_ver"] != mission["cords_ver_dest"]:
continue
table = connection["planets"]
planet = table.find_one(cords_hor=mission["cords_hor"], cords_ver=mission["cords_ver"])
if planet is None:
continue
planet_id = planet["id"]
vops_waiting = False
table = connection["virtualops"]
for vops in table.find(mission_id=mission_id):
if vops["tr_status"] == 0:
vops_waiting = True
if vops_waiting:
continue
table = connection["transactions"]
vops = table.find_one(tr_var1=mission_id, tr_status=2)
if vops is None:
continue
#if mission["busy_until_return"] is None:
# continue
if mission["busy_until_return"] is not None and mission["busy_until_return"] > time_now:
continue
if mission["mission_type"] in ["support"]:
continue
print(mission["mission_type"])
table = connection['ships']
print({"id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"])})
if not test_mode:
# check if there is enough resources on the starting planet - if not return False
(new_qty_coal,new_qty_ore,new_qty_copper,new_qty_uranium,level_base,level_research,level_shipyard) = get_resource_levels(planet_id, parameter, time_now)
fin_qty_coal = float(new_qty_coal) + ship["qyt_coal"]
fin_qty_ore = float(new_qty_ore) + ship["qyt_ore"]
fin_qty_copper = float(new_qty_copper) + ship["qyt_copper"]
fin_qty_uranium = float(new_qty_uranium) + ship["qyt_uranium"]
table = connection['ships']
table.update({"id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"]),
"qyt_coal": 0, "qyt_ore": 0, "qyt_copper": 0,
"qyt_uranium": 0},['id'])
table = connection['planets']
data = dict(id=planet_id,qyt_ore=fin_qty_ore,qyt_coal=fin_qty_coal,qyt_copper=fin_qty_copper,qyt_uranium=fin_qty_uranium,last_update=time_now)
table.update(data,['id'])
if apply_fix3:
print("apply_fix3")
if not test_mode:
table = connection["stardust"]
table.delete()
table = connection["users"]
update_amount = []
for row in table.find():
stardust_trx = []
old_stardust = row["stardust"]
amount = 0
if row["date"] < datetime(2019, 7, 22, 10, 0, 0):
table = connection["transactions"]
new_user_trx = table.find_one(user=row["username"], tr_type="newuser", tr_status=1)
if new_user_trx is not None:
amount = int(10e8)
if not test_mode:
stardust_trx.append({"trx": new_user_trx["trx"], "tr_type": "gift", "tr_status": 1, "date": new_user_trx["date"],
"from_user":"nextcolony", "to_user":row["username"], "amount":int(10e8)})
table = connection["transfers"]
for transfer in table.find(user=row["username"], tr_status=1):
steem_amount = Amount(transfer["amount"])
transfer_amount = int(float(steem_amount) * 100 * 1e8)
if transfer["trx"] in ["1ac6dcbb7f4f4fc3864c570d909bc0081e80c997",
"581c991f617393ebe87f305f724500edbc2b0181", "3d4dff0f428952dbc8b92d251bb029b2bb24774a",
"e7f108ceb69df1d502f502325c53f1bb8b4a308d", "1c79290c4697ecb9aeffd9ab0a22091cba7c780f",
"85950718febcb51ccdaad75dedcf4c0219d8ae95", "9c0afd10af78d414766a85b54f4ea27042b0f6c0",
"8d8d8925fb80839c53c1023d1927fbfaac78a335"]:
continue
amount += transfer_amount
if not test_mode:
stardust_trx.append({"trx": transfer["trx"], "tr_type": "shop", "tr_status": 1, "date": transfer["date"], "to_user":transfer["user"], "amount":transfer_amount})
table = connection["transactions"]
for trx in table.find(user=row["username"], tr_type="transferstardust", tr_status=1):
transfer_amount = int(float(trx["tr_var1"]) * 1e8)
amount -= transfer_amount
if not test_mode:
stardust_trx.append({"trx": trx["trx"], "tr_type": "transfer", "tr_status": 1, "date": trx["date"],
"from_user":trx["user"], "to_user":trx["tr_var2"], "amount":transfer_amount})
for trx in table.find(tr_var2=row["username"], tr_type="transferstardust", tr_status=1):
transfer_amount = int(float(trx["tr_var1"]) * 1e8)
amount += transfer_amount
if amount > 0:
update_amount.append({"id": row["id"], "stardust": amount})
if old_stardust is not None:
print("%s %d -> %d" % (row["username"], old_stardust, amount))
if len(stardust_trx) > 0 and not test_mode:
table = connection["stardust"]
connection.begin()
for data in stardust_trx:
table.insert(data)
connection.commit()
stardust_trx = []
if not test_mode:
table = connection["users"]
connection.begin()
for user in update_amount:
table.update(user, ["id"])
connection.commit()
if apply_fix4:
print("apply_fix4")
auctions = [{"username": "sternenkrieger", "amount": 1379, "date": datetime(2019,3,25,8,39,0)},
{"username": "govinda71", "amount": 1350, "date": datetime(2019,3,26,17,56,0)},
{"username": "reggaemuffin", "amount": 1337, "date": datetime(2019,3,26,18,14,0)},
{"username": "mancer-sm-alt", "amount": 1500, "date": datetime(2019,4,7,22,20,0)},
{"username": "uraniumfuture", "amount": 1410, "date": datetime(2019,4,7,23,37,0)},
{"username": "urachem", "amount": 1503, "date": datetime(2019,4,8,8,42,0)},
{"username": "xx0xx", "amount": 30015, "date": datetime(2019,4,21,22,27,0)}]
table = connection["users"]
update_amount = []
stardust_trx = []
for user in auctions:
user_data = table.find_one(username=user["username"])
amount = user_data["stardust"] + int(user["amount"] * 100 * 1e8)
stardust_data = table.find_one(to_user=user["username"], tr_type="auction")
if stardust_data is None:
update_amount.append({"id": user_data["id"], "stardust": amount})
stardust_trx.append({"tr_type": "auction", "tr_status": 1, "date": user["date"], "from_user": "nextcolony", "to_user":user["username"], "amount":int(user["amount"] * 100 * 1e8)})
if not test_mode:
table = connection["stardust"]
connection.begin()
for data in stardust_trx:
table.insert(data)
stardust_trx = []
table = connection["users"]
for user in update_amount:
table.update(user, ["id"])
connection.commit()
if apply_fix5:
print("apply_fix5")
table = connection["shop"]
booster_list = ["booster_01", "booster_02", "booster_03"]
for b in booster_list:
booster = table.find_one(itemid=b)
table.update({"itemid": b, "boost_percentage": booster["boost_percentage"] * 2}, ["itemid"])
table = connection["planets"]
for planet in table.find(boost_percentage={">": 0}):
if planet["boost_percentage"] == 0:
continue
table.update({"id": planet["id"], "boost_percentage": planet["boost_percentage"] * 2}, ["id"])
if apply_fix6:
print("Apply fix6")
table = connection["ships"]
ships = []
for ship in table.find(mission_id={'not': None}):
ships.append(ship["id"])
print("%d ships found" % len(ships))
cnt = 0
ship_cnt = 0
for shipid in ships:
cnt += 1
if cnt % 10000 == 0:
print("%d/%d ships processed" % (cnt, len(ships)))
table = connection["ships"]
ship = table.find_one(id=shipid)
if ship is None:
continue
if ship["mission_busy_until"] > time_now:
continue
mission_id = ship["mission_id"]
table = connection["missions"]
mission = table.find_one(mission_id=mission_id)
if mission is None:
continue
if ship["user"] != mission["user"]:
continue
if ship["cords_hor"] != mission["cords_hor_dest"]:
continue
if ship["cords_ver"] != mission["cords_ver_dest"]:
continue
if ship["qyt_uranium"] == 0:
continue
table = connection["planets"]
planet = table.find_one(cords_hor=mission["cords_hor"], cords_ver=mission["cords_ver"])
if planet is None:
continue
planet_id = planet["id"]
vops_waiting = False
table = connection["virtualops"]
for vops in table.find(mission_id=mission_id):
if vops["tr_status"] == 0:
vops_waiting = True
if vops_waiting:
continue
table = connection["transactions"]
vops = table.find_one(tr_var1=mission_id, tr_status=2)
if vops is not None:
continue
#vops = table.find_one(tr_var1=mission_id, tr_status=1)
#if vops is not None:
# print(vops)
#if mission["busy_until_return"] is None:
# continue
if mission["busy_until_return"] is not None and mission["busy_until_return"] > time_now:
continue
if mission["mission_type"] in ["support"]:
continue
print(mission["mission_type"])
table = connection['ships']
ship_cnt += 1
print({"cnt": ship_cnt, "id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"]), "planet_id": planet_id, "user": mission["user"]})
if not test_mode:
# check if there is enough resources on the starting planet - if not return False
(new_qty_coal,new_qty_ore,new_qty_copper,new_qty_uranium,level_base,level_research,level_shipyard) = get_resource_levels(planet_id, parameter, time_now)
fin_qty_coal = float(new_qty_coal) + ship["qyt_coal"]
fin_qty_ore = float(new_qty_ore) + ship["qyt_ore"]
fin_qty_copper = float(new_qty_copper) + ship["qyt_copper"]
fin_qty_uranium = float(new_qty_uranium) + ship["qyt_uranium"]
table = connection['ships']
table.update({"id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"]),
"qyt_coal": 0, "qyt_ore": 0, "qyt_copper": 0,
"qyt_uranium": 0},['id'])
table = connection['planets']
data = dict(id=planet_id,qyt_ore=fin_qty_ore,qyt_coal=fin_qty_coal,qyt_copper=fin_qty_copper,qyt_uranium=fin_qty_uranium,last_update=time_now)
table.update(data,['id'])
if apply_fix7:
print("Apply fix7")
table = connection["ships"]
ships = []
for ship in table.find(mission_id={'not': None}):
ships.append(ship["id"])
print("%d ships found" % len(ships))
cnt = 0
ship_cnt = 0
for shipid in ships:
cnt += 1
if cnt % 10000 == 0:
print("%d/%d ships processed" % (cnt, len(ships)))
table = connection["ships"]
ship = table.find_one(id=shipid)
if ship is None:
continue
if ship["mission_busy_until"] > time_now:
continue
mission_id = ship["mission_id"]
table = connection["missions"]
mission = table.find_one(mission_id=mission_id)
if mission is None:
continue
if ship["user"] != mission["user"]:
continue
if ship["cords_hor"] != mission["cords_hor_dest"]:
continue
if ship["cords_ver"] != mission["cords_ver_dest"]:
continue
if ship["qyt_uranium"] == 0:
continue
table = connection["planets"]
planet = table.find_one(cords_hor=mission["cords_hor"], cords_ver=mission["cords_ver"])
if planet is None:
continue
planet_id = planet["id"]
vops_waiting = False
table = connection["virtualops"]
for vops in table.find(mission_id=mission_id):
if vops["tr_status"] == 0:
vops_waiting = True
if vops_waiting:
continue
if mission["busy_until_return"] is not None and mission["busy_until_return"] > time_now:
continue
if mission["mission_type"] in ["support"]:
continue
print(mission["mission_type"])
table = connection['ships']
ship_cnt += 1
print({"cnt": ship_cnt, "id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"]), "planet_id": planet_id, "user": mission["user"]})
if not test_mode:
# check if there is enough resources on the starting planet - if not return False
(new_qty_coal,new_qty_ore,new_qty_copper,new_qty_uranium,level_base,level_research,level_shipyard) = get_resource_levels(planet_id, parameter, time_now)
fin_qty_coal = float(new_qty_coal) + ship["qyt_coal"]
fin_qty_ore = float(new_qty_ore) + ship["qyt_ore"]
fin_qty_copper = float(new_qty_copper) + ship["qyt_copper"]
fin_qty_uranium = float(new_qty_uranium) + ship["qyt_uranium"]
table = connection['ships']
table.update({"id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"]),
"qyt_coal": 0, "qyt_ore": 0, "qyt_copper": 0,
"qyt_uranium": 0},['id'])
table = connection['planets']
data = dict(id=planet_id,qyt_ore=fin_qty_ore,qyt_coal=fin_qty_coal,qyt_copper=fin_qty_copper,qyt_uranium=fin_qty_uranium,last_update=time_now)
table.update(data,['id'])
if apply_fix8:
print("Apply fix8")
table = connection["ships"]
ships = []
for ship in table.find(mission_id={'not': None}):
ships.append(ship["id"])
print("%d ships found" % len(ships))
cnt = 0
ship_cnt = 0
for shipid in ships:
cnt += 1
if cnt % 10000 == 0:
print("%d/%d ships processed" % (cnt, len(ships)))
table = connection["ships"]
ship = table.find_one(id=shipid)
if ship is None:
continue
if ship["mission_busy_until"] > time_now:
continue
mission_id = ship["mission_id"]
table = connection["missions"]
mission = table.find_one(mission_id=mission_id)
if mission is None:
continue
if ship["user"] != mission["user"]:
continue
if ship["cords_hor"] != mission["cords_hor_dest"]:
continue
if ship["cords_ver"] != mission["cords_ver_dest"]:
continue
if ship["qyt_uranium"] == 0:
continue
table = connection["planets"]
planet = table.find_one(cords_hor=mission["cords_hor"], cords_ver=mission["cords_ver"])
if planet is None:
continue
planet_id = planet["id"]
vops_waiting = False
table = connection["virtualops"]
for vops in table.find(mission_id=mission_id):
if vops["tr_status"] == 0:
vops_waiting = True
if vops_waiting:
continue
if mission["busy_until_return"] is not None and mission["busy_until_return"] > time_now:
continue
if mission["mission_type"] in ["support"]:
continue
print(mission["mission_type"])
table = connection['ships']
ship_cnt += 1
print({"cnt": ship_cnt, "id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"]), "planet_id": planet_id, "user": mission["user"]})
if not test_mode:
# check if there is enough resources on the starting planet - if not return False
(new_qty_coal,new_qty_ore,new_qty_copper,new_qty_uranium,level_base,level_research,level_shipyard) = get_resource_levels(planet_id, parameter, time_now)
fin_qty_coal = float(new_qty_coal) + ship["qyt_coal"]
fin_qty_ore = float(new_qty_ore) + ship["qyt_ore"]
fin_qty_copper = float(new_qty_copper) + ship["qyt_copper"]
fin_qty_uranium = float(new_qty_uranium) + ship["qyt_uranium"]
table = connection['ships']
table.update({"id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"]),
"qyt_coal": 0, "qyt_ore": 0, "qyt_copper": 0,
"qyt_uranium": 0},['id'])
table = connection['planets']
data = dict(id=planet_id,qyt_ore=fin_qty_ore,qyt_coal=fin_qty_coal,qyt_copper=fin_qty_copper,qyt_uranium=fin_qty_uranium,last_update=time_now)
table.update(data,['id'])
if apply_fix9:
print("Apply fix9")
table = connection["ships"]
ships = []
for ship in table.find(mission_id={'not': None}):
ships.append(ship["id"])
print("%d ships found" % len(ships))
cnt = 0
ship_cnt = 0
for shipid in ships:
cnt += 1
if cnt % 10000 == 0:
print("%d/%d ships processed" % (cnt, len(ships)))
table = connection["ships"]
ship = table.find_one(id=shipid)
if ship is None:
continue
if ship["mission_busy_until"] > time_now:
continue
mission_id = ship["mission_id"]
table = connection["missions"]
mission = table.find_one(mission_id=mission_id)
if mission is None:
continue
if ship["user"] != mission["user"]:
continue
if ship["cords_hor"] != mission["cords_hor_dest"]:
continue
if ship["cords_ver"] != mission["cords_ver_dest"]:
continue
if ship["qyt_uranium"] == 0:
continue
table = connection["planets"]
planet = table.find_one(cords_hor=mission["cords_hor"], cords_ver=mission["cords_ver"])
if planet is None:
continue
planet_id = planet["id"]
vops_waiting = False
table = connection["virtualops"]
for vops in table.find(mission_id=mission_id):
if vops["tr_status"] == 0:
vops_waiting = True
if vops_waiting:
continue
if mission["busy_until_return"] is not None and mission["busy_until_return"] > time_now:
continue
if mission["mission_type"] in ["support"]:
continue
print(mission["mission_type"])
table = connection['ships']
ship_cnt += 1
print({"cnt": ship_cnt, "id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"]), "planet_id": planet_id, "user": mission["user"]})
if not test_mode:
# check if there is enough resources on the starting planet - if not return False
(new_qty_coal,new_qty_ore,new_qty_copper,new_qty_uranium,level_base,level_research,level_shipyard) = get_resource_levels(planet_id, parameter, time_now)
fin_qty_coal = float(new_qty_coal) + ship["qyt_coal"]
fin_qty_ore = float(new_qty_ore) + ship["qyt_ore"]
fin_qty_copper = float(new_qty_copper) + ship["qyt_copper"]
fin_qty_uranium = float(new_qty_uranium) + ship["qyt_uranium"]
table = connection['ships']
table.update({"id": str(shipid), "cords_hor": int(mission["cords_hor"]), "cords_ver": int(mission["cords_ver"]),
"qyt_coal": 0, "qyt_ore": 0, "qyt_copper": 0,
"qyt_uranium": 0},['id'])
table = connection['planets']
data = dict(id=planet_id,qyt_ore=fin_qty_ore,qyt_coal=fin_qty_coal,qyt_copper=fin_qty_copper,qyt_uranium=fin_qty_uranium,last_update=time_now)
table.update(data,['id'])