tradedangerous 12.0.5__py3-none-any.whl → 12.0.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of tradedangerous might be problematic. Click here for more details.
- tradedangerous/cache.py +135 -133
- tradedangerous/commands/buildcache_cmd.py +7 -7
- tradedangerous/commands/buy_cmd.py +4 -4
- tradedangerous/commands/export_cmd.py +11 -11
- tradedangerous/commands/import_cmd.py +12 -12
- tradedangerous/commands/market_cmd.py +17 -17
- tradedangerous/commands/olddata_cmd.py +18 -18
- tradedangerous/commands/rares_cmd.py +30 -30
- tradedangerous/commands/run_cmd.py +21 -21
- tradedangerous/commands/sell_cmd.py +5 -5
- tradedangerous/corrections.py +1 -1
- tradedangerous/csvexport.py +20 -20
- tradedangerous/db/adapter.py +9 -9
- tradedangerous/db/config.py +4 -4
- tradedangerous/db/engine.py +12 -12
- tradedangerous/db/lifecycle.py +28 -28
- tradedangerous/db/orm_models.py +42 -42
- tradedangerous/db/paths.py +3 -3
- tradedangerous/plugins/eddblink_plug.py +108 -253
- tradedangerous/plugins/spansh_plug.py +254 -254
- tradedangerous/prices.py +21 -21
- tradedangerous/tradedb.py +85 -85
- tradedangerous/tradeenv.py +2 -2
- tradedangerous/version.py +1 -1
- {tradedangerous-12.0.5.dist-info → tradedangerous-12.0.7.dist-info}/METADATA +1 -1
- {tradedangerous-12.0.5.dist-info → tradedangerous-12.0.7.dist-info}/RECORD +30 -30
- {tradedangerous-12.0.5.dist-info → tradedangerous-12.0.7.dist-info}/WHEEL +0 -0
- {tradedangerous-12.0.5.dist-info → tradedangerous-12.0.7.dist-info}/entry_points.txt +0 -0
- {tradedangerous-12.0.5.dist-info → tradedangerous-12.0.7.dist-info}/licenses/LICENSE +0 -0
- {tradedangerous-12.0.5.dist-info → tradedangerous-12.0.7.dist-info}/top_level.txt +0 -0
tradedangerous/prices.py
CHANGED
|
@@ -40,39 +40,39 @@ def dumpPrices(
|
|
|
40
40
|
If stationID is not None, only the specified station is dumped.
|
|
41
41
|
If file is not None, outputs to the given file handle.
|
|
42
42
|
"""
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
withTimes = elementMask & Element.timestamp
|
|
45
45
|
getBlanks = elementMask & Element.blanks
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
# ORM queries to build lookup dicts
|
|
48
48
|
systems = dict(
|
|
49
49
|
session.query(SA.System.system_id, SA.System.name).all()
|
|
50
50
|
)
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
stations = {
|
|
53
53
|
ID: [name, systems.get(sysID)]
|
|
54
54
|
for ID, name, sysID in session.query(
|
|
55
55
|
SA.Station.station_id, SA.Station.name, SA.Station.system_id
|
|
56
56
|
).all()
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
categories = dict(
|
|
60
60
|
session.query(SA.Category.category_id, SA.Category.name).all()
|
|
61
61
|
)
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
items = {
|
|
64
64
|
ID: [name, catID, categories[catID]]
|
|
65
65
|
for ID, name, catID in session.query(
|
|
66
66
|
SA.Item.item_id, SA.Item.name, SA.Item.category_id
|
|
67
67
|
).all()
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
# find longest item name (for formatting)
|
|
71
71
|
longestName = max(items.values(), key=lambda ent: len(ent[0]))
|
|
72
72
|
longestNameLen = len(longestName[0])
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
defaultDemandVal = 0 if defaultZero else -1
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
# Build the main query
|
|
77
77
|
q = (
|
|
78
78
|
session.query(
|
|
@@ -97,19 +97,19 @@ def dumpPrices(
|
|
|
97
97
|
.join(SA.System, SA.System.system_id == SA.Station.system_id)
|
|
98
98
|
.order_by(SA.Station.station_id, SA.Category.name, SA.Item.ui_order)
|
|
99
99
|
)
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
if stationID:
|
|
102
102
|
q = q.filter(SA.StationItem.station_id == stationID)
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
# Set up output
|
|
105
105
|
if not file:
|
|
106
106
|
file = sys.stdout
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
if stationID:
|
|
109
109
|
stationSet = str(stations[stationID])
|
|
110
110
|
else:
|
|
111
111
|
stationSet = "ALL Systems/Stations"
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
file.write(
|
|
114
114
|
"# TradeDangerous prices for {}\n"
|
|
115
115
|
"\n"
|
|
@@ -127,11 +127,11 @@ def dumpPrices(
|
|
|
127
127
|
"the file is loaded.\n"
|
|
128
128
|
"\n".format(stationSet)
|
|
129
129
|
)
|
|
130
|
-
|
|
130
|
+
|
|
131
131
|
levelDesc = "?0LMH"
|
|
132
132
|
maxCrWidth = 7
|
|
133
133
|
levelWidth = 9
|
|
134
|
-
|
|
134
|
+
|
|
135
135
|
outFmt = (
|
|
136
136
|
" {{:<{width}}}"
|
|
137
137
|
" {{:>{crwidth}}}"
|
|
@@ -153,11 +153,11 @@ def dumpPrices(
|
|
|
153
153
|
"Timestamp",
|
|
154
154
|
)
|
|
155
155
|
file.write('#' + header[1:])
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
naIQL = "-"
|
|
158
158
|
unkIQL = "?"
|
|
159
159
|
defIQL = "?" if not defaultZero else "-"
|
|
160
|
-
|
|
160
|
+
|
|
161
161
|
# Main loop — stream results instead of preloading
|
|
162
162
|
output = ""
|
|
163
163
|
lastStn, lastCat = None, None
|
|
@@ -175,17 +175,17 @@ def dumpPrices(
|
|
|
175
175
|
raise TradeException(
|
|
176
176
|
f"Station {station} (ID {stnID}) is linked to a system with no name."
|
|
177
177
|
)
|
|
178
|
-
|
|
178
|
+
|
|
179
179
|
if stnID != lastStn:
|
|
180
180
|
file.write(output)
|
|
181
181
|
output = f"\n\n@ {system.upper()}/{station}\n"
|
|
182
182
|
lastStn = stnID
|
|
183
183
|
lastCat = None
|
|
184
|
-
|
|
184
|
+
|
|
185
185
|
if catID != lastCat:
|
|
186
186
|
output += f" + {category}\n"
|
|
187
187
|
lastCat = catID
|
|
188
|
-
|
|
188
|
+
|
|
189
189
|
demandCr = row.demand_price or 0
|
|
190
190
|
supplyCr = row.supply_price or 0
|
|
191
191
|
demandUnits = row.demand_units or defaultDemandVal
|
|
@@ -206,8 +206,8 @@ def dumpPrices(
|
|
|
206
206
|
else (f"{demandUnits if demandUnits >= 0 else '?'}{levelDesc[demandLevel+1]}")
|
|
207
207
|
)
|
|
208
208
|
supplyStr = naIQL
|
|
209
|
-
|
|
209
|
+
|
|
210
210
|
modified = row.modified or ""
|
|
211
211
|
output += outFmt.format(item, demandCr, supplyCr, demandStr, supplyStr, modified)
|
|
212
|
-
|
|
212
|
+
|
|
213
213
|
file.write(output)
|
tradedangerous/tradedb.py
CHANGED
|
@@ -577,8 +577,8 @@ class TradeDB:
|
|
|
577
577
|
defaultDB = 'TradeDangerous.db'
|
|
578
578
|
# File containing SQL to build the DB cache from
|
|
579
579
|
defaultSQL = 'TradeDangerous.sql'
|
|
580
|
-
# File containing text description of prices
|
|
581
|
-
defaultPrices = 'TradeDangerous.prices'
|
|
580
|
+
# # File containing text description of prices
|
|
581
|
+
# defaultPrices = 'TradeDangerous.prices'
|
|
582
582
|
# array containing standard tables, csvfilename and tablename
|
|
583
583
|
# WARNING: order is important because of dependencies!
|
|
584
584
|
defaultTables = (
|
|
@@ -612,36 +612,36 @@ class TradeDB:
|
|
|
612
612
|
self.engine = None
|
|
613
613
|
self.Session = None
|
|
614
614
|
self.tradingCount = None
|
|
615
|
-
|
|
615
|
+
|
|
616
616
|
# Environment
|
|
617
617
|
tdenv = tdenv or TradeEnv(debug=(debug or 0))
|
|
618
618
|
self.tdenv = tdenv
|
|
619
|
-
|
|
619
|
+
|
|
620
620
|
# --- Path setup (unchanged) ---
|
|
621
621
|
self.templatePath = Path(tdenv.templateDir).resolve()
|
|
622
622
|
self.dataPath = dataPath = fs.ensurefolder(tdenv.dataDir)
|
|
623
623
|
self.csvPath = fs.ensurefolder(tdenv.csvDir)
|
|
624
|
-
|
|
624
|
+
|
|
625
625
|
fs.copy_if_newer(self.templatePath / "Added.csv", self.csvPath / "Added.csv")
|
|
626
626
|
fs.copy_if_newer(self.templatePath / "RareItem.csv", self.csvPath / "RareItem.csv")
|
|
627
627
|
fs.copy_if_newer(self.templatePath / "Category.csv", self.csvPath / "Category.csv")
|
|
628
628
|
fs.copy_if_newer(self.templatePath / "TradeDangerous.sql", self.dataPath / "TradeDangerous.sql")
|
|
629
|
-
|
|
629
|
+
|
|
630
630
|
self.dbPath = Path(tdenv.dbFilename or dataPath / TradeDB.defaultDB)
|
|
631
631
|
self.sqlPath = dataPath / Path(tdenv.sqlFilename or TradeDB.defaultSQL)
|
|
632
|
-
pricePath = Path(tdenv.pricesFilename or TradeDB.defaultPrices)
|
|
633
|
-
self.pricesPath = dataPath / pricePath
|
|
634
|
-
|
|
632
|
+
# pricePath = Path(tdenv.pricesFilename or TradeDB.defaultPrices)
|
|
633
|
+
# self.pricesPath = dataPath / pricePath
|
|
634
|
+
|
|
635
635
|
self.importTables = [
|
|
636
636
|
(str(self.csvPath / Path(fn)), tn)
|
|
637
637
|
for fn, tn in TradeDB.defaultTables
|
|
638
638
|
]
|
|
639
639
|
self.importPaths = {tn: tp for tp, tn in self.importTables}
|
|
640
|
-
|
|
640
|
+
|
|
641
641
|
self.dbFilename = str(self.dbPath)
|
|
642
642
|
self.sqlFilename = str(self.sqlPath)
|
|
643
|
-
self.pricesFilename = str(self.pricesPath)
|
|
644
|
-
|
|
643
|
+
# self.pricesFilename = str(self.pricesPath)
|
|
644
|
+
|
|
645
645
|
# --- Cache attributes (unchanged) ---
|
|
646
646
|
self.avgSelling, self.avgBuying = None, None
|
|
647
647
|
self.tradingStationCount = 0
|
|
@@ -657,18 +657,18 @@ class TradeDB:
|
|
|
657
657
|
self.itemByFDevID = None
|
|
658
658
|
self.rareItemByID = None
|
|
659
659
|
self.rareItemByName = None
|
|
660
|
-
|
|
660
|
+
|
|
661
661
|
# --- Engine bootstrap ---
|
|
662
662
|
from .db import make_engine_from_config, get_session_factory
|
|
663
663
|
from .db.paths import resolve_data_dir
|
|
664
664
|
import os
|
|
665
|
-
|
|
665
|
+
|
|
666
666
|
# Determine user's real invocation directory, not venv/bin
|
|
667
667
|
user_cwd = Path(os.getenv("PWD", Path.cwd()))
|
|
668
668
|
data_dir = user_cwd / "data"
|
|
669
|
-
|
|
669
|
+
|
|
670
670
|
cfg = os.environ.get("TD_DB_CONFIG") or str(data_dir / "db_config.ini")
|
|
671
|
-
|
|
671
|
+
|
|
672
672
|
self.engine = make_engine_from_config(cfg)
|
|
673
673
|
self.Session = get_session_factory(self.engine)
|
|
674
674
|
|
|
@@ -677,7 +677,7 @@ class TradeDB:
|
|
|
677
677
|
if load:
|
|
678
678
|
self.reloadCache()
|
|
679
679
|
self.load(maxSystemLinkLy=tdenv.maxSystemLinkLy)
|
|
680
|
-
|
|
680
|
+
|
|
681
681
|
# ------------------------------------------------------------------
|
|
682
682
|
# Legacy compatibility dataPath shim
|
|
683
683
|
# ------------------------------------------------------------------
|
|
@@ -695,7 +695,7 @@ class TradeDB:
|
|
|
695
695
|
return self.tdenv.dataDir
|
|
696
696
|
# Final fallback (first run, pre-bootstrap)
|
|
697
697
|
return Path("./data")
|
|
698
|
-
|
|
698
|
+
|
|
699
699
|
|
|
700
700
|
@staticmethod
|
|
701
701
|
def calculateDistance2(lx, ly, lz, rx, ry, rz):
|
|
@@ -723,7 +723,7 @@ class TradeDB:
|
|
|
723
723
|
if not self.engine:
|
|
724
724
|
raise TradeException("Database engine not initialised")
|
|
725
725
|
return self.Session()
|
|
726
|
-
|
|
726
|
+
|
|
727
727
|
def query(self, sql: str, *params):
|
|
728
728
|
"""
|
|
729
729
|
Execute a SQL statement via the SQLAlchemy engine and return the result cursor.
|
|
@@ -731,32 +731,32 @@ class TradeDB:
|
|
|
731
731
|
from sqlalchemy import text
|
|
732
732
|
with self.engine.connect() as conn:
|
|
733
733
|
return conn.execute(text(sql), params)
|
|
734
|
-
|
|
734
|
+
|
|
735
735
|
def queryColumn(self, sql: str, *params):
|
|
736
736
|
"""
|
|
737
737
|
Execute a SQL statement and return the first column of the first row.
|
|
738
738
|
"""
|
|
739
739
|
result = self.query(sql, *params).first()
|
|
740
740
|
return result[0] if result else None
|
|
741
|
-
|
|
741
|
+
|
|
742
742
|
|
|
743
743
|
def reloadCache(self):
|
|
744
744
|
"""
|
|
745
745
|
Ensure DB is present and minimally populated using the central policy.
|
|
746
|
-
|
|
746
|
+
|
|
747
747
|
Delegates sanity checks to lifecycle.ensure_fresh_db (seconds-only checks):
|
|
748
748
|
- core tables exist (System, Station, Category, Item, StationItem)
|
|
749
749
|
- each has a primary key
|
|
750
750
|
- seed rows exist (Category > 0, System > 0)
|
|
751
751
|
- cheap connectivity probe
|
|
752
|
-
|
|
752
|
+
|
|
753
753
|
If checks fail (or lifecycle decides to force), it will call buildCache(self, self.tdenv)
|
|
754
754
|
to reset/populate via the authoritative path. Otherwise it is a no-op.
|
|
755
755
|
"""
|
|
756
756
|
from tradedangerous.db.lifecycle import ensure_fresh_db
|
|
757
|
-
|
|
757
|
+
|
|
758
758
|
self.tdenv.DEBUG0("reloadCache: engine URL = {}", str(self.engine.url))
|
|
759
|
-
|
|
759
|
+
|
|
760
760
|
try:
|
|
761
761
|
summary = ensure_fresh_db(
|
|
762
762
|
backend=self.engine.dialect.name,
|
|
@@ -794,7 +794,7 @@ class TradeDB:
|
|
|
794
794
|
addedByID[row.added_id] = row.name
|
|
795
795
|
self.addedByID = addedByID
|
|
796
796
|
self.tdenv.DEBUG1("Loaded {:n} Addeds", len(addedByID))
|
|
797
|
-
|
|
797
|
+
|
|
798
798
|
|
|
799
799
|
def lookupAdded(self, name):
|
|
800
800
|
name = name.lower()
|
|
@@ -835,10 +835,10 @@ class TradeDB:
|
|
|
835
835
|
)
|
|
836
836
|
systemByID[row.system_id] = system
|
|
837
837
|
systemByName[row.name.upper()] = system
|
|
838
|
-
|
|
838
|
+
|
|
839
839
|
self.systemByID, self.systemByName = systemByID, systemByName
|
|
840
840
|
self.tdenv.DEBUG1("Loaded {:n} Systems", len(systemByID))
|
|
841
|
-
|
|
841
|
+
|
|
842
842
|
|
|
843
843
|
def lookupSystem(self, key):
|
|
844
844
|
"""
|
|
@@ -879,21 +879,21 @@ class TradeDB:
|
|
|
879
879
|
session.commit()
|
|
880
880
|
else:
|
|
881
881
|
session.flush()
|
|
882
|
-
|
|
882
|
+
|
|
883
883
|
ID = orm_system.system_id
|
|
884
|
-
|
|
884
|
+
|
|
885
885
|
# Maintain legacy wrapper + caches (added_id always None now)
|
|
886
886
|
system = System(ID, name.upper(), x, y, z, None)
|
|
887
887
|
self.systemByID[ID] = system
|
|
888
888
|
self.systemByName[system.dbname] = system
|
|
889
|
-
|
|
889
|
+
|
|
890
890
|
self.tdenv.NOTE(
|
|
891
891
|
"Added new system #{}: {} [{},{},{}]",
|
|
892
892
|
ID, name, x, y, z
|
|
893
893
|
)
|
|
894
894
|
self.stellarGrid = None
|
|
895
895
|
return system
|
|
896
|
-
|
|
896
|
+
|
|
897
897
|
|
|
898
898
|
def updateLocalSystem(
|
|
899
899
|
self, system,
|
|
@@ -906,27 +906,27 @@ class TradeDB:
|
|
|
906
906
|
"""
|
|
907
907
|
oldname = system.dbname
|
|
908
908
|
dbname = name.upper()
|
|
909
|
-
|
|
909
|
+
|
|
910
910
|
if not force:
|
|
911
911
|
if (oldname == dbname and
|
|
912
912
|
system.posX == x and
|
|
913
913
|
system.posY == y and
|
|
914
914
|
system.posZ == z):
|
|
915
915
|
return False
|
|
916
|
-
|
|
916
|
+
|
|
917
917
|
del self.systemByName[oldname]
|
|
918
|
-
|
|
918
|
+
|
|
919
919
|
with self.Session() as session:
|
|
920
920
|
# Find Added row for added_id
|
|
921
921
|
added_row = session.query(Added).filter(Added.name == added).first()
|
|
922
922
|
if not added_row:
|
|
923
923
|
raise TradeException(f"Added entry not found: {added}")
|
|
924
|
-
|
|
924
|
+
|
|
925
925
|
# Load ORM System row
|
|
926
926
|
orm_system = session.get(SA_System, system.ID)
|
|
927
927
|
if not orm_system:
|
|
928
928
|
raise TradeException(f"System ID not found: {system.ID}")
|
|
929
|
-
|
|
929
|
+
|
|
930
930
|
# Apply updates
|
|
931
931
|
orm_system.name = dbname
|
|
932
932
|
orm_system.pos_x = x
|
|
@@ -934,27 +934,27 @@ class TradeDB:
|
|
|
934
934
|
orm_system.pos_z = z
|
|
935
935
|
orm_system.added_id = added_row.added_id
|
|
936
936
|
orm_system.modified = None if modified == 'now' else modified
|
|
937
|
-
|
|
937
|
+
|
|
938
938
|
if commit:
|
|
939
939
|
session.commit()
|
|
940
940
|
else:
|
|
941
941
|
session.flush()
|
|
942
|
-
|
|
942
|
+
|
|
943
943
|
self.tdenv.NOTE(
|
|
944
944
|
"{} (#{}) updated in {}: {}, {}, {}, {}, {}, {}",
|
|
945
945
|
oldname, system.ID,
|
|
946
946
|
self.dbPath if self.tdenv.detail > 1 else "local db",
|
|
947
947
|
dbname, x, y, z, added, modified,
|
|
948
948
|
)
|
|
949
|
-
|
|
949
|
+
|
|
950
950
|
# Update wrapper caches
|
|
951
951
|
system.name = dbname
|
|
952
952
|
system.posX, system.posY, system.posZ = x, y, z
|
|
953
953
|
system.addedID = added_row.added_id
|
|
954
954
|
self.systemByName[dbname] = system
|
|
955
|
-
|
|
955
|
+
|
|
956
956
|
return True
|
|
957
|
-
|
|
957
|
+
|
|
958
958
|
|
|
959
959
|
def removeLocalSystem(
|
|
960
960
|
self, system,
|
|
@@ -965,7 +965,7 @@ class TradeDB:
|
|
|
965
965
|
for stn in self.stations():
|
|
966
966
|
if stn.system == system:
|
|
967
967
|
self.removeLocalStation(stn, commit=False)
|
|
968
|
-
|
|
968
|
+
|
|
969
969
|
with self.Session() as session:
|
|
970
970
|
orm_system = session.get(SA_System, system.ID)
|
|
971
971
|
if orm_system:
|
|
@@ -974,20 +974,20 @@ class TradeDB:
|
|
|
974
974
|
session.commit()
|
|
975
975
|
else:
|
|
976
976
|
session.flush()
|
|
977
|
-
|
|
977
|
+
|
|
978
978
|
# Update caches
|
|
979
979
|
del self.systemByName[system.dbname]
|
|
980
980
|
del self.systemByID[system.ID]
|
|
981
|
-
|
|
981
|
+
|
|
982
982
|
self.tdenv.NOTE(
|
|
983
983
|
"{} (#{}) deleted from {}",
|
|
984
984
|
system.name, system.ID,
|
|
985
985
|
self.dbPath if self.tdenv.detail > 1 else "local db",
|
|
986
986
|
)
|
|
987
|
-
|
|
987
|
+
|
|
988
988
|
system.dbname = "DELETED " + system.dbname
|
|
989
989
|
del system
|
|
990
|
-
|
|
990
|
+
|
|
991
991
|
|
|
992
992
|
def __buildStellarGrid(self):
|
|
993
993
|
"""
|
|
@@ -1257,12 +1257,12 @@ class TradeDB:
|
|
|
1257
1257
|
stationByID = {}
|
|
1258
1258
|
systemByID = self.systemByID
|
|
1259
1259
|
self.tradingStationCount = 0
|
|
1260
|
-
|
|
1260
|
+
|
|
1261
1261
|
# Fleet Carriers are station type 24.
|
|
1262
1262
|
# Odyssey settlements are station type 25.
|
|
1263
1263
|
# Assume type 0 (Unknown) are also Fleet Carriers.
|
|
1264
1264
|
types = {'fleet-carrier': [24, 0], 'odyssey': [25]}
|
|
1265
|
-
|
|
1265
|
+
|
|
1266
1266
|
with self.Session() as session:
|
|
1267
1267
|
# Query all stations
|
|
1268
1268
|
rows = session.query(
|
|
@@ -1296,7 +1296,7 @@ class TradeDB:
|
|
|
1296
1296
|
0, None,
|
|
1297
1297
|
)
|
|
1298
1298
|
stationByID[ID] = station
|
|
1299
|
-
|
|
1299
|
+
|
|
1300
1300
|
# Trading station info
|
|
1301
1301
|
tradingCount = 0
|
|
1302
1302
|
rows = (
|
|
@@ -1309,13 +1309,13 @@ class TradeDB:
|
|
|
1309
1309
|
.group_by(SA_StationItem.station_id)
|
|
1310
1310
|
.having(func.count() > 0)
|
|
1311
1311
|
)
|
|
1312
|
-
|
|
1312
|
+
|
|
1313
1313
|
for ID, itemCount, dataAge in rows:
|
|
1314
1314
|
station = stationByID[ID]
|
|
1315
1315
|
station.itemCount = itemCount
|
|
1316
1316
|
station.dataAge = dataAge
|
|
1317
1317
|
tradingCount += 1
|
|
1318
|
-
|
|
1318
|
+
|
|
1319
1319
|
self.stationByID = stationByID
|
|
1320
1320
|
self.tradingStationCount = tradingCount
|
|
1321
1321
|
self.tdenv.DEBUG1("Loaded {:n} Stations", len(stationByID))
|
|
@@ -1366,14 +1366,14 @@ class TradeDB:
|
|
|
1366
1366
|
assert planetary in "?YN"
|
|
1367
1367
|
assert fleet in "?YN"
|
|
1368
1368
|
assert odyssey in "?YN"
|
|
1369
|
-
|
|
1369
|
+
|
|
1370
1370
|
# Type mapping
|
|
1371
1371
|
type_id = 0
|
|
1372
1372
|
if fleet == 'Y':
|
|
1373
1373
|
type_id = 24
|
|
1374
1374
|
if odyssey == 'Y':
|
|
1375
1375
|
type_id = 25
|
|
1376
|
-
|
|
1376
|
+
|
|
1377
1377
|
with self.Session() as session:
|
|
1378
1378
|
orm_station = SA_Station(
|
|
1379
1379
|
name=name,
|
|
@@ -1397,7 +1397,7 @@ class TradeDB:
|
|
|
1397
1397
|
else:
|
|
1398
1398
|
session.flush()
|
|
1399
1399
|
ID = orm_station.station_id
|
|
1400
|
-
|
|
1400
|
+
|
|
1401
1401
|
# Legacy wrapper object
|
|
1402
1402
|
station = Station(
|
|
1403
1403
|
ID, system, name,
|
|
@@ -1417,7 +1417,7 @@ class TradeDB:
|
|
|
1417
1417
|
dataAge=0,
|
|
1418
1418
|
)
|
|
1419
1419
|
self.stationByID[ID] = station
|
|
1420
|
-
|
|
1420
|
+
|
|
1421
1421
|
self.tdenv.NOTE(
|
|
1422
1422
|
"{} (#{}) added to {}: "
|
|
1423
1423
|
"ls={}, mkt={}, bm={}, yard={}, pad={}, "
|
|
@@ -1454,23 +1454,23 @@ class TradeDB:
|
|
|
1454
1454
|
Alter the properties of a station in-memory and in the DB using SQLAlchemy.
|
|
1455
1455
|
"""
|
|
1456
1456
|
changes = []
|
|
1457
|
-
|
|
1457
|
+
|
|
1458
1458
|
def _changed(label, old, new):
|
|
1459
1459
|
changes.append(f"{label}('{old}'=>'{new}')")
|
|
1460
|
-
|
|
1460
|
+
|
|
1461
1461
|
# Mutate wrapper + record changes
|
|
1462
1462
|
if name is not None:
|
|
1463
1463
|
if force or name.upper() != station.dbname.upper():
|
|
1464
1464
|
_changed("name", station.dbname, name)
|
|
1465
1465
|
station.dbname = name
|
|
1466
|
-
|
|
1466
|
+
|
|
1467
1467
|
if lsFromStar is not None:
|
|
1468
1468
|
assert lsFromStar >= 0
|
|
1469
1469
|
if lsFromStar != station.lsFromStar:
|
|
1470
1470
|
if lsFromStar > 0 or force:
|
|
1471
1471
|
_changed("ls", station.lsFromStar, lsFromStar)
|
|
1472
1472
|
station.lsFromStar = lsFromStar
|
|
1473
|
-
|
|
1473
|
+
|
|
1474
1474
|
def _check_setting(label, attr_name, newValue, allowed):
|
|
1475
1475
|
if newValue is not None:
|
|
1476
1476
|
newValue = newValue.upper()
|
|
@@ -1479,7 +1479,7 @@ class TradeDB:
|
|
|
1479
1479
|
if newValue != oldValue and (force or newValue != '?'):
|
|
1480
1480
|
_changed(label, oldValue, newValue)
|
|
1481
1481
|
setattr(station, attr_name, newValue)
|
|
1482
|
-
|
|
1482
|
+
|
|
1483
1483
|
_check_setting("pad", "maxPadSize", maxPadSize, TradeDB.padSizes)
|
|
1484
1484
|
_check_setting("mkt", "market", market, TradeDB.marketStates)
|
|
1485
1485
|
_check_setting("blk", "blackMarket", blackMarket, TradeDB.marketStates)
|
|
@@ -1491,15 +1491,15 @@ class TradeDB:
|
|
|
1491
1491
|
_check_setting("plt", "planetary", planetary, TradeDB.planetStates)
|
|
1492
1492
|
_check_setting("flc", "fleet", fleet, TradeDB.fleetStates)
|
|
1493
1493
|
_check_setting("ody", "odyssey", odyssey, TradeDB.odysseyStates)
|
|
1494
|
-
|
|
1494
|
+
|
|
1495
1495
|
if not changes:
|
|
1496
1496
|
return False
|
|
1497
|
-
|
|
1497
|
+
|
|
1498
1498
|
with self.Session() as session:
|
|
1499
1499
|
orm_station = session.get(SA_Station, station.ID)
|
|
1500
1500
|
if not orm_station:
|
|
1501
1501
|
raise TradeException(f"Station ID not found: {station.ID}")
|
|
1502
|
-
|
|
1502
|
+
|
|
1503
1503
|
orm_station.name = station.dbname
|
|
1504
1504
|
orm_station.system_id = station.system.ID
|
|
1505
1505
|
orm_station.ls_from_star = station.lsFromStar
|
|
@@ -1517,19 +1517,19 @@ class TradeDB:
|
|
|
1517
1517
|
25 if station.odyssey == 'Y' else 0
|
|
1518
1518
|
)
|
|
1519
1519
|
orm_station.modified = None if modified == 'now' else modified
|
|
1520
|
-
|
|
1520
|
+
|
|
1521
1521
|
if commit:
|
|
1522
1522
|
session.commit()
|
|
1523
1523
|
else:
|
|
1524
1524
|
session.flush()
|
|
1525
|
-
|
|
1525
|
+
|
|
1526
1526
|
self.tdenv.NOTE(
|
|
1527
1527
|
"{} (#{}) updated in {}: {}",
|
|
1528
1528
|
station.name(), station.ID,
|
|
1529
1529
|
self.dbPath if self.tdenv.detail > 1 else "local db",
|
|
1530
1530
|
", ".join(changes)
|
|
1531
1531
|
)
|
|
1532
|
-
|
|
1532
|
+
|
|
1533
1533
|
return True
|
|
1534
1534
|
|
|
1535
1535
|
def removeLocalStation(self, station, commit=True):
|
|
@@ -1541,11 +1541,11 @@ class TradeDB:
|
|
|
1541
1541
|
system = station.system
|
|
1542
1542
|
if station in system.stations:
|
|
1543
1543
|
system.stations.remove(station)
|
|
1544
|
-
|
|
1544
|
+
|
|
1545
1545
|
# Remove from ID lookup cache
|
|
1546
1546
|
if station.ID in self.stationByID:
|
|
1547
1547
|
del self.stationByID[station.ID]
|
|
1548
|
-
|
|
1548
|
+
|
|
1549
1549
|
# Delete from DB
|
|
1550
1550
|
with self.Session() as session:
|
|
1551
1551
|
orm_station = session.get(SA_Station, station.ID)
|
|
@@ -1555,13 +1555,13 @@ class TradeDB:
|
|
|
1555
1555
|
session.commit()
|
|
1556
1556
|
else:
|
|
1557
1557
|
session.flush()
|
|
1558
|
-
|
|
1558
|
+
|
|
1559
1559
|
self.tdenv.NOTE(
|
|
1560
1560
|
"{} (#{}) deleted from {}",
|
|
1561
1561
|
station.name(), station.ID,
|
|
1562
1562
|
self.dbPath if self.tdenv.detail > 1 else "local db",
|
|
1563
1563
|
)
|
|
1564
|
-
|
|
1564
|
+
|
|
1565
1565
|
station.dbname = "DELETED " + station.dbname
|
|
1566
1566
|
del station
|
|
1567
1567
|
|
|
@@ -1914,9 +1914,9 @@ class TradeDB:
|
|
|
1914
1914
|
row.ship_id: Ship(row.ship_id, row.name, row.cost, stations=[])
|
|
1915
1915
|
for row in rows
|
|
1916
1916
|
}
|
|
1917
|
-
|
|
1917
|
+
|
|
1918
1918
|
self.tdenv.DEBUG1("Loaded {} Ships", len(self.shipByID))
|
|
1919
|
-
|
|
1919
|
+
|
|
1920
1920
|
|
|
1921
1921
|
def lookupShip(self, name):
|
|
1922
1922
|
"""
|
|
@@ -1994,11 +1994,11 @@ class TradeDB:
|
|
|
1994
1994
|
if fdevID:
|
|
1995
1995
|
itemByFDevID[fdevID] = item
|
|
1996
1996
|
category.items.append(item)
|
|
1997
|
-
|
|
1997
|
+
|
|
1998
1998
|
self.itemByID = itemByID
|
|
1999
1999
|
self.itemByName = itemByName
|
|
2000
2000
|
self.itemByFDevID = itemByFDevID
|
|
2001
|
-
|
|
2001
|
+
|
|
2002
2002
|
self.tdenv.DEBUG1("Loaded {:n} Items", len(self.itemByID))
|
|
2003
2003
|
|
|
2004
2004
|
def lookupItem(self, name):
|
|
@@ -2017,7 +2017,7 @@ class TradeDB:
|
|
|
2017
2017
|
"""
|
|
2018
2018
|
if not self.avgSelling:
|
|
2019
2019
|
self.avgSelling = {itemID: 0 for itemID in self.itemByID}
|
|
2020
|
-
|
|
2020
|
+
|
|
2021
2021
|
with self.Session() as session:
|
|
2022
2022
|
rows = (
|
|
2023
2023
|
session.query(
|
|
@@ -2034,16 +2034,16 @@ class TradeDB:
|
|
|
2034
2034
|
)
|
|
2035
2035
|
for ID, cr in rows:
|
|
2036
2036
|
self.avgSelling[ID] = int(cr)
|
|
2037
|
-
|
|
2037
|
+
|
|
2038
2038
|
return self.avgSelling
|
|
2039
|
-
|
|
2039
|
+
|
|
2040
2040
|
def getAverageBuying(self):
|
|
2041
2041
|
"""
|
|
2042
2042
|
Query the database for average buying prices of all items using SQLAlchemy.
|
|
2043
2043
|
"""
|
|
2044
2044
|
if not self.avgBuying:
|
|
2045
2045
|
self.avgBuying = {itemID: 0 for itemID in self.itemByID}
|
|
2046
|
-
|
|
2046
|
+
|
|
2047
2047
|
with self.Session() as session:
|
|
2048
2048
|
rows = (
|
|
2049
2049
|
session.query(
|
|
@@ -2060,9 +2060,9 @@ class TradeDB:
|
|
|
2060
2060
|
)
|
|
2061
2061
|
for ID, cr in rows:
|
|
2062
2062
|
self.avgBuying[ID] = int(cr)
|
|
2063
|
-
|
|
2063
|
+
|
|
2064
2064
|
return self.avgBuying
|
|
2065
|
-
|
|
2065
|
+
|
|
2066
2066
|
|
|
2067
2067
|
############################################################
|
|
2068
2068
|
# Rare Items
|
|
@@ -2073,7 +2073,7 @@ class TradeDB:
|
|
|
2073
2073
|
"""
|
|
2074
2074
|
rareItemByID, rareItemByName = {}, {}
|
|
2075
2075
|
stationByID = self.stationByID
|
|
2076
|
-
|
|
2076
|
+
|
|
2077
2077
|
with self.Session() as session:
|
|
2078
2078
|
rows = session.query(
|
|
2079
2079
|
SA_RareItem.rare_id,
|
|
@@ -2098,12 +2098,12 @@ class TradeDB:
|
|
|
2098
2098
|
)
|
|
2099
2099
|
rareItemByID[ID] = rare
|
|
2100
2100
|
rareItemByName[name] = rare
|
|
2101
|
-
|
|
2101
|
+
|
|
2102
2102
|
self.rareItemByID = rareItemByID
|
|
2103
2103
|
self.rareItemByName = rareItemByName
|
|
2104
|
-
|
|
2104
|
+
|
|
2105
2105
|
self.tdenv.DEBUG1("Loaded {:n} RareItems", len(rareItemByID))
|
|
2106
|
-
|
|
2106
|
+
|
|
2107
2107
|
|
|
2108
2108
|
############################################################
|
|
2109
2109
|
# Price data.
|