Skip to content

Commit

Permalink
Merge branch 'master' of bitbucket.org:kfsone/tradedangerous into devel
Browse files Browse the repository at this point in the history
Conflicts:
	data/Added.csv
  • Loading branch information
bgol committed Nov 23, 2014
2 parents 6b8b4ad + c85ed3f commit ef49c95
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.0.5 Nov 22 2014 (w/Gamma 1)
. (kfsone) Added "import" sub-command for loading 1+ stations from a file
. (kfsone) Added "--height" (-H) option to update GUI
. (kfsone) Added "--front" (-F) to keep the update gui infront of TD
. (kfsone) Added Pilot's Federation/Jameson Memorial

v6.0.4 Nov 21 2014 (Beta 3.9.1)
. (kfsone) Added "sell" command (find places to sell a specific item)
. (kfsone) Reactive Armor changed to Reactive Armour
Expand Down
2 changes: 1 addition & 1 deletion cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def buildCache(tdenv, dbPath, sqlPath, pricesPath, importTables, defaultZero=Fal

######################################################################

def importDataFromFile(tdenv, tdb, path, reset=False):
def importDataFromFile(tdb, tdenv, path, reset=False):
"""
Import price data from a file on a per-station basis,
that is when a new station is encountered, delete any
Expand Down
1 change: 1 addition & 0 deletions commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'buildcache',
'buy',
'local',
'import',
'nav',
'run',
'sell',
Expand Down
33 changes: 33 additions & 0 deletions commands/import_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import absolute_import, with_statement, print_function, division, unicode_literals
from commands.parsing import MutuallyExclusiveGroup, ParseArgument
from commands.exceptions import *
import math

import cache
from pathlib import Path

######################################################################
# Parser config

help=(
"Imports price data from a '.prices' format file "
"without affecting data for stations not included "
"in the import file."
)
name='import'
epilog=None
wantsTradeDB=True
arguments = [
ParseArgument('filename', help='Name of the file to read.', type=str),
]
switches = [
]

######################################################################
# Perform query and populate result set

def run(results, cmdenv, tdb):
filePath = Path(cmdenv.filename)
cache.importDataFromFile(tdb, cmdenv, filePath)
return None

19 changes: 17 additions & 2 deletions commands/update_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@
default=False,
dest='gui',
),
ParseArgument('--height', '-H',
help="[GUI] Specify height of the window",
type=int,
default=800,
),
ParseArgument('--front', '-F',
help=(
"[GUI] Keep the GUI infront of other windows; "
"this allows you to put the window infront of "
"the game UI if you run the game in windowed mode."
),
action='store_true',
default=False,
dest='alwaysOnTop',
),
MutuallyExclusiveGroup(
ParseArgument('--sublime',
help='Like --editor but uses Sublime Text (2 or 3), which is nice.',
Expand Down Expand Up @@ -250,7 +265,7 @@ def editUpdate(tdb, cmdenv, stationID):
"Suit you, sir! Oh!"
])))
else:
cache.importDataFromFile(cmdenv, tdb, tmpPath)
cache.importDataFromFile(tdb, cmdenv, tmpPath)

tmpPath.unlink()
tmpPath = None
Expand All @@ -269,7 +284,7 @@ def guidedUpdate(tdb, cmdenv):
try:
render(tdb, cmdenv, tmpPath)
cmdenv.DEBUG0("Got results, importing")
cache.importDataFromFile(cmdenv, tdb, tmpPath)
cache.importDataFromFile(tdb, cmdenv, tmpPath)
except Exception as e:
print("*** ERROR ENCOUNTERED ***")
print("*** YOUR UPDATES WILL BE SAVED AS {} ***".format(
Expand Down
20 changes: 18 additions & 2 deletions commands/update_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import tkinter.messagebox as mbox
import tkinter.ttk as ttk
import sqlite3
import re
from pathlib import Path

class Item(object):
Expand All @@ -17,7 +18,14 @@ class UpdateGUI(tk.Canvas):
"""

def __init__(self, root, tdb, cmdenv):
super().__init__(root, borderwidth=0, width=500, height=440)
width = cmdenv.width or 512
height = cmdenv.height or 640
sticky = 1 if cmdenv.alwaysOnTop else 0

super().__init__(root, borderwidth=0, width=width, height=height)
root.geometry("{}x{}-0+0".format(
width+32, height
))

self.root = root
self.tdb = tdb
Expand All @@ -32,6 +40,8 @@ def __init__(self, root, tdb, cmdenv):
self.results = None
self.headings = []

root.wm_attributes("-topmost", sticky)

self.bind_all("<MouseWheel>", self.onMouseWheel)
self.vsb = tk.Scrollbar(root, orient="vertical", command=self.yview)
self.configure(yscrollcommand=self.vsb.set)
Expand Down Expand Up @@ -218,7 +228,7 @@ def addHeading(text):
addHeading("Paying")
addHeading("Asking")
addHeading("Demand")
addHeading("Stock")
addHeading("Supply")
self.endRow()


Expand Down Expand Up @@ -338,6 +348,12 @@ def getResults(self):

if asking == 0:
stock = "-"
elif not stock:
stock = "?"

if re.match('^\d+$', stock):
if int(stock) != 0:
stock += '?'

txt += (" {item:<30s} "
"{paying:>10} "
Expand Down
2 changes: 2 additions & 0 deletions data/Added.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ unq:name
'Beta2 (outside Beta3)'
'Beta2 (outside Beta3)-Inferred'
'Beta2 (unverified)'
<<<<<<< HEAD
'Beta2-Inferred'
'Beta3'
'Beta3-Inferred'
'Beyond The Pill (unverified)-Inferred'
'Gamma1'
'Not Present'
'Premium Beta1'
'Premium Beta2'
Expand Down
41 changes: 34 additions & 7 deletions data/Station.csv
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ [email protected]_id,unq:name,ls_from_star
'61 Virginis','Artsebarsky Station',0.0
'68 Draconis','Gaspar De Lemos Port',0.0
'70 Virginis','Reis Platform',0.0
'Aiabiko','Gooch Terminal',0.0
'Aiabiko','White Orbital',0.0
'Aiabiko','Maxwell Orbital',0.0
'Aiabiko','Treshchov Port',0.0
'Aiabiko','Jett Ring',0.0
'Aiabiko','Haisheng Port',0.0
'Aiabiko','Savitskaya Station',0.0
'Aiabiko','Haber Dock',0.0
'Aiabiko','Weston Dock',0.0
'Abrogo','Laing Hub',0.0
'Acihaut','Cuffey Plant',0.0
'Acurukunabogamal','Aguirre Terminal',0.0
Expand Down Expand Up @@ -56,7 +65,11 @@ [email protected]_id,unq:name,ls_from_star
'Chapoyo','Piccard Port',0.0
'Chara','Reilly Refinery',0.0
'Chaxiraxi','Brother''s Progress',0.0
'Chemaku','Bartoe Platform',0.0
'Chemaku','Crampton Port',0.0
'Chemaku','Kaku Orbital',0.0
'Chemaku','Ferguson City',0.0
'Chemaku','Ewald City',0.0
'Chemaku','Lawson Station',0.0
'Chi Herculis','Gorbatko Reserve',0.0
'Chongquan','Eisele Park',0.0
'CM Draco','Anderson Escape',0.0
Expand Down Expand Up @@ -160,7 +173,7 @@ [email protected]_id,unq:name,ls_from_star
'LFT 820','Bailey Landing',0.0
'LFT 859','Stross City',0.0
'LFT 880','Baker Platform',0.0
'LFT 926','Onizuka Platform',0.0
'LFT 926','Meredith City',0.0
'LFT 945','Hahn Base',0.0
'LFT 992','Szulkin mines',0.0
'LHS 1065','Hornblower Platform',0.0
Expand Down Expand Up @@ -247,7 +260,7 @@ [email protected]_id,unq:name,ls_from_star
'Marasing','Thiele Enterprise',0.0
'Markanomovoy','Compton Dock',0.0
'Marsinatani','Hewish Relay',0.0
'MAUJINAGOTO','Halsell Point',0.0
'Maujinagoto','Halsell Point',0.0
'MCC 858','Jacquard Orbital',0.0
'Melcior','Goddard Dock',0.0
'Meliae','Shawl Beacon',0.0
Expand All @@ -267,6 +280,11 @@ [email protected]_id,unq:name,ls_from_star
'NLTT 46621','Hope Point',0.0
'NLTT 48502','Webb Holdings',0.0
'NLTT 53889','Roosa Platform',0.0
'Nuenets','Shriver Hub',0.0
'Nuenets','Laliberte Enterprise',0.0
'Nuenets','Harbaugh Port',0.0,
'Nuenets','Forrester Dock',0.0
'Nuenets','Ryazanski Dock',0.0
'Nuwang','Schade Outpost',0.0
'Nzambassee','Garriott Stop',0.0
'Okinoukhe','Stableford Ring',0.0
Expand Down Expand Up @@ -295,10 +313,18 @@ [email protected]_id,unq:name,ls_from_star
'Ross 1015','Bowersox Mines',0.0
'Ross 104','Glenn Dock',0.0
'Ross 1051','Abetti Platform',0.0
'ROSS 1057','Wang Estate',0.0
'Ross 1057','Wang Estate',0.0
'Ross 128','Warren Prison Mine',0.0
'Ross 130','Huxley Relay',0.0
'Ross 210','Viktorenko Park',0.0
'Ross 210','Swift Gateway',0.0
'Ross 210','Fernandes De Queiros Dock',0.0
'Ross 210','Fu City',0.0
'Ross 210','Tokubei Ring',0.0
'Ross 210','Lunan Dock',0.0
'Ross 210','Chebyshev Ring',0.0
'Ross 210','Quinn Dock',0.0
'Ross 210','Clauss Gateway',0.0
'Ross 210','Lanier Orbital',0.0
'Ross 211','Chilton Vision',0.0
'Ross 318','Koch Hub',0.0
'Ross 446','Nowak Laboratory',0.0
Expand All @@ -312,6 +338,7 @@ [email protected]_id,unq:name,ls_from_star
'Shama','Clairaut Port',0.0
'Shebayeb','Volta Landing',0.0
'Sheela Na Gig','Birkhoff Terminal',0.0
'Shinrarta Dezhra','Jameson Memorial',0.0
'Sigma Bootis','Meikle Platform',0.0
'Slatus','Hoffman Orbital',0.0
'Sofagre','Markov Park',0.0
Expand Down Expand Up @@ -350,10 +377,10 @@ [email protected]_id,unq:name,ls_from_star
'Wanggu','Besonders Port',0.0
'Wei Jung','Cooper Dock',0.0
'Wikmeang','Ivanov Hub',0.0
'WISE 1506+7027','Silverberg Relay',0.0
'Wise 1506+7027','Silverberg Relay',0.0
'Wolf 1409','Carter Vision',0.0
'Wolf 1478','Franklin Orbital',0.0
'WOLF 248','Hencke Centre',0.0
'Wolf 248','Hencke Centre',0.0
'Wolf 294','Hippalus Station',0.0
'Wolf 359','Lomas Orbiter',0.0
'Wolf 393','Lichtenberg Horizons',0.0
Expand Down
4 changes: 2 additions & 2 deletions data/System.csv
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ unq:name,pos_x,pos_y,pos_z,[email protected]_id,modified
'Kaal',-18.34375,66.71875,-21.59375,'Beta3','2014-11-01 06:36:37'
'Kaha''i',-7.03125,60.8125,-21.8125,'Beta3','2014-11-01 06:36:37'
'Kali',33.59375,57.375,-28.84375,'Beta3','2014-11-01 06:36:37'
'Kamchaultultula',-82.0625,1.625,-14.4375,'Beta2','2014-11-01 06:36:37'
'Aiabiko',-82.0625,1.625,-14.4375,'Beta2','2014-11-01 06:36:37'
'Kanati',74.125,46.1875,-19.46875,'Beta3','2014-11-01 06:36:37'
'Kanos',41.375,53.65625,-12.65625,'Beta3','2014-11-01 06:36:37'
'Karovices',-102.4375,6.9375,-14.875,'Beta3','2014-11-01 06:36:37'
Expand Down Expand Up @@ -768,7 +768,7 @@ unq:name,pos_x,pos_y,pos_z,[email protected]_id,modified
'LTT 4447',68.0625,50.40625,23.15625,'Beta3','2014-11-01 06:36:37'
'LTT 4461',49.625,44.84375,15.65625,'Beta3','2014-11-01 06:36:37'
'LTT 4527',49.9375,48.53125,17.28125,'Beta3','2014-11-01 06:36:37'
'LTT 4549',55.71875,17.59375,27.15625,'Beta3','2014-11-01 06:36:37'
'Shinrarta Dezhra',55.71875,17.59375,27.15625,'Gamma1','2014-11-01 06:36:37'
'LTT 4730',22.1875,30.875,9.84375,'Beta3','2014-11-01 06:36:37'
'LTT 4772',50.78125,63.21875,26.53125,'Beta3','2014-11-01 06:36:37'
'LTT 4898',43.0625,39.71875,27.71875,'Beta3','2014-11-01 06:36:37'
Expand Down
5 changes: 5 additions & 0 deletions data/corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
DELETED = -111

systems = {
"LTT 4549": "Shinrarta Dezhra",
"KAMCHAULTULTULA": "Aiabiko",
#ADD_SYSTEMS_HERE
}

stations = {
"STYX/STYX-STATION": "Searfoss Plant",
"STYX/CHI HUB": "Searfoss Plant",
"STYX/CHU HUB": "Searfoss Plant",
"LFT 926/ONIZUKA PLATFORM": "Meredith City",
#ADD_STATIONS_HERE
}

categories = {
Expand Down
62 changes: 62 additions & 0 deletions misc/edstarquery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#! /usr/bin/env python3

from __future__ import absolute_import, with_statement, print_function, division, unicode_literals

from urllib.parse import urlencode
from urllib.request import Request, urlopen
import json

class EDStarQuery(object):
url = 'http://edstarcoordinator.com/api.asmx/GetSystems'

def __init__(self, detail=2, test=False, known=1, confidence=0, **kwargs):
self.params = {
'data': {
'ver': 2,
'test': test,
'outputmode': detail,
'filter': {
'knownstatus': known,
'cr': confidence,
}
}
}
for k, v in kwargs.items():
self.params.filter[k] = v

self.jsData = None


def fetch(self):
params = json.dumps(self.params).encode('utf-8')
request = Request(EDStarQuery.url, params, {
'Content-Type': 'application/json;charset=utf-8',
'Content-Length': len(params)
})

with urlopen(request, params) as stream:
self.jsData = stream.read()

data = json.loads(self.jsData.decode())['d']
inputNo = 0
self.status = data['status']['input'][inputNo]['status']

return data


if __name__ == "__main__":
edsq = EDStarQuery(test=False, confidence=0)
data = edsq.fetch()

if edsq.status['statusnum'] != 0:
raise Exception("Query failed: {} ({})".format(
edsq.status['msg'],
edsq.status['statusnum'],
))

date = data['date']
systems = data['systems']

for sysinfo in systems:
print(sysinfo['id'], sysinfo['name'], sysinfo['coord'])

2 changes: 1 addition & 1 deletion tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def reloadCache(self):
return

self.tdenv.DEBUG0(".prices has changed: re-importing")
cache.importDataFromFile(self.tdenv, self, self.pricesPath, reset=True)
cache.importDataFromFile(self, self.tdenv, self.pricesPath, reset=True)
return

self.tdenv.DEBUG0("Rebuilding DB Cache [{}]", str(changedPaths))
Expand Down

0 comments on commit ef49c95

Please sign in to comment.