Git Product home page Git Product logo

Comments (8)

eyeonus avatar eyeonus commented on July 23, 2024 2

I'm working on it.
This is what it looks like at this point, mostly as proof of concept that it actually does work:

>trade olddata --raw
('table', [('Station', 'DistLy', 'Age/days', 'StnLs', 'Pad', 'Plt', 'Flc'), ('Chih Hiner/Soukup Town', 0.0, 708.4715489004739, '15', 'Lrg', 'Yes', 'No'), ('HIP 4073/Herbig Settlement', 0.0, 708.0695002893917, '3.34K', 'Lrg', 'Yes', 'No'), ('Segovas/Thollon Works', 0.0, 708.0026831598952, '822', 'Lrg', 'Yes', 'No'), ("HIP 109642/Mayor's Claim", 0.0, 700.1933544562198, '3.17K', 'Med', 'No', 'No'), ('Col 285 Sector SE-Q d5-134/Baker Arena', 0.0, 684.7466067709029, '3.20K', 'Lrg', 'Yes', 'No'), ('Volupana/Vercors Prospect', 0.0, 682.8277063081041, '235', 'Lrg', 'Yes', 'No'), ('HIP 16272/Stone Port', 0.0, 677.6948475115933, '3.60K', 'Med', 'No', 'No'), ('HIP 862/Carpenter Keep', 0.0, 674.8596623265184, '1.41K', 'Lrg', 'Yes', 'No'), ('Ambibarii/Steinmuller Camp', 0.0, 669.7662826972082, '2.18K', 'Lrg', 'Yes', 'No'), ('Kremovi/Brothers Settlement', 0.0, 660.9491067710333, '464K', 'Lrg', 'Yes', 'No'), ('Jurasmat/Brooks Plant', 0.0, 659.001433160156, '26', 'Lrg', 'Yes', 'No'), ('Ekoimudji/Coppel Beacon', 0.0, 651.8908776044846, '35', 'Lrg', 'Yes', 'No'), ('Quile/Messerschmitt Point', 0.0, 647.3532965858467, '110', 'Lrg', 'Yes', 'No'), ('Arevat/Gaultier de Varennes Relay', 0.0, 646.7622664934024, '482', 'Lrg', 'Yes', 'No'), ('Tricasses/Banks Landing', 0.0, 638.9739331598394, '288', 'Lrg', 'Yes', 'No'), ('Dinde/Youll Penal colony', 0.0, 637.8445002897643, '33K', 'Lrg', 'Yes', 'No'), ('Ten Gu/Kummer Observatory', 0.0, 636.7051947340369, '403', 'Lrg', 'Yes', 'No'), ('Uzumoku/Noguchi Base', 0.0, 629.7080882526934, '505K', 'Lrg', 'Yes', 'No'), ('Naporimui/Hewish Mines', 0.0, 622.6532965856604, '17K', 'Med', 'No', 'No'), ('HIP 2725/Marques Keep', 0.0, 622.6404840857722, '60', 'Lrg', 'Yes', 'No')])
>trade olddata
Station                                Age/days      StnLs Pad Plt Flc
----------------------------------------------------------------------
Chih Hiner/Soukup Town                   708.47         15 Lrg Yes  No
HIP 4073/Herbig Settlement               708.07      3.34K Lrg Yes  No
Segovas/Thollon Works                    708.00        822 Lrg Yes  No
HIP 109642/Mayor's Claim                 700.19      3.17K Med  No  No
Col 285 Sector SE-Q d5-134/Baker Arena   684.75      3.20K Lrg Yes  No
Volupana/Vercors Prospect                682.83        235 Lrg Yes  No
HIP 16272/Stone Port                     677.69      3.60K Med  No  No
HIP 862/Carpenter Keep                   674.86      1.41K Lrg Yes  No
Ambibarii/Steinmuller Camp               669.77      2.18K Lrg Yes  No
Kremovi/Brothers Settlement              660.95       464K Lrg Yes  No
Jurasmat/Brooks Plant                    659.00         26 Lrg Yes  No
Ekoimudji/Coppel Beacon                  651.89         35 Lrg Yes  No
Quile/Messerschmitt Point                647.35        110 Lrg Yes  No
Arevat/Gaultier de Varennes Relay        646.76        482 Lrg Yes  No
Tricasses/Banks Landing                  638.97        288 Lrg Yes  No
Dinde/Youll Penal colony                 637.84        33K Lrg Yes  No
Ten Gu/Kummer Observatory                636.70        403 Lrg Yes  No
Uzumoku/Noguchi Base                     629.71       505K Lrg Yes  No
Naporimui/Hewish Mines                   622.65        17K Med  No  No
HIP 2725/Marques Keep                    622.64         60 Lrg Yes  No

from trade-dangerous.

eyeonus avatar eyeonus commented on July 23, 2024 1

Regardless of which command(s) you want to get json for, the best option is to trace the code to the point where it's about to pass a big list of results (which helpfully is usually if not always called "results") to something that does output formatting, and sending that list of results to a json formatter instead when some cmd parameter is passed.

IIRC, python objects in general can be directly converted to json, and dict objects definitely can, so the json output formatter could probably be as simple as:

  1. Convert result list to json using python's native converter.
  2. Print the conversion to stdout or a file.
  3. ????
  4. Profit.

from trade-dangerous.

eyeonus avatar eyeonus commented on July 23, 2024

I'm not certain what output you're referring to, but if you post an example with the current output and the same information in the desired json format, I can look into when I have time.

Also, don't be afraid to code it yourself. It's pretty likely you'd have it coded more quickly than I, and 90% of programming is fixing the bugs found during testing, anyway.

from trade-dangerous.

timkinnane avatar timkinnane commented on July 23, 2024

Thanks @eyeonus - I'm trying to get programatic access to the results of trade queries via Javascript.

At the moment I'm executing a python process from Node.js and capturing output like...

Station                                         Cost      Units Age/days      StnLs B/mkt Pad Plt
-------------------------------------------------------------------------------------------------
Hahgwe/Barcelos Camp                           4,539          0     0.50        321    No Lrg Yes
Ross 665/Malpighi Oasis                        4,539          0    24.28      1.50K    No Lrg Yes

For now I just hacked in a distinct | separator between columns so I can parse it back into an object using regex. To be universally portable without those workarounds, I was hoping to get JSON values in their original types (not formatted for readable display). Something like:

{
  "results": [
    {
      "Station": "Hahgwe/Barcelos Camp",
      "Cost": 4539,
      "Units": 0,
      "Age/days": 0.50,
      "StnLs": 321,
      "B/mkt": false,
      "Pad": "Lrg",
      "Plt": true
    },
    {
      "Station": "Ross 665/Malpighi Oasis",
      "Cost": 4539,
      "Units": 0,
      "Age/days": 24.28,
      "StnLs": 150000,
      "B/mkt": false,
      "Pad": "Lrg",
      "Plt": true
    }
  ]
}

I had a look at coding myself, but I can't get my head around where to divert the logic producing the result set columns. e.g. in formatting.py or higher at the nav_cmd.py level?

from trade-dangerous.

eyeonus avatar eyeonus commented on July 23, 2024

It depends on which output you want to redirect.

For example, to redirect the output from the "trade" command, you would want to modify the "render" method in the "commands/trade.py" module.

(Or, alternatively, figure out where that particular method gets called, build a different json render method, and have the calling program call the json render instead when the json option is enabled.)

from trade-dangerous.

timkinnane avatar timkinnane commented on July 23, 2024

FYI, I never learned much Python and couldn't figure out how to convert results. Instead I wrote some helpers to read the printed results and convert back into objects in Javascript. Not ideal, but it works for my immediate needs. If anyone asks I can share back here, but it's not in a state to make public yet.

from trade-dangerous.

timkinnane avatar timkinnane commented on July 23, 2024

Oops didn't mean to close. This would still be a nice to have, so I'll reopen in the event someone with the required skill can pick it up.

from trade-dangerous.

Tromador avatar Tromador commented on July 23, 2024

Closing. Ancient, not been touched in years and we are making moves away from prices anywa6.

from trade-dangerous.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.