Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
fix: replace commodity name with symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbruford committed Aug 8, 2020
1 parent 283eda9 commit b98ef22
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/semver": "^5.5.0",
"angular2-template-loader": "^0.6.2",
"awesome-typescript-loader": "^5.2.1",
"cmdr-journal": "^7.0.1",
"cmdr-journal": "^7.1.1",
"copy-webpack-plugin": "^5.1.1",
"cross-env": "^5.2.0",
"css-loader": "^1.0.1",
Expand Down
10 changes: 10 additions & 0 deletions src/app/journal/eddn-commodities.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type EDDNCommodity = {
name: string;
meanPrice: number;
buyPrice: number;
stock: number;
stockBracket: number;
sellPrice: number;
demand: number;
demandBracket: number;
};
40 changes: 30 additions & 10 deletions src/app/journal/eddn.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Location,
CarrierJump,
MarketJSON,
COMMODITY_MAP,
} from "cmdr-journal";
import { HttpClient } from "@angular/common/http";
import { LoggerService } from "../core/services/logger.service";
Expand Down Expand Up @@ -134,6 +135,34 @@ export class EDDNService {
}
delete marketData.event;

const commodityData: EDDNCommodity[] = [];

marketData.Items.forEach((item) => {
const commoditySymbol = COMMODITY_MAP.get(item.id)?.symbol;

if (
commoditySymbol &&
!isNaN(item.MeanPrice) &&
!isNaN(item.BuyPrice) &&
!isNaN(item.Stock) &&
!isNaN(item.StockBracket) &&
!isNaN(item.SellPrice) &&
!isNaN(item.Demand) &&
!isNaN(item.DemandBracket)
) {
commodityData.push({
name: commoditySymbol,
meanPrice: item.MeanPrice,
buyPrice: item.BuyPrice,
stock: item.Stock,
stockBracket: item.StockBracket,
sellPrice: item.SellPrice,
demand: item.Demand,
demandBracket: item.DemandBracket,
});
}
});

let submission = {
$schemaRef: process.env.EDDN_COMMODITY_ENDPOINT,
header: {
Expand All @@ -146,16 +175,7 @@ export class EDDNService {
stationName: marketData.StationName,
marketId: marketData.MarketID,
timestamp: marketData.timestamp,
commodities: marketData.Items.map((item) => ({
name: item.Name,
meanPrice: item.MeanPrice,
buyPrice: item.BuyPrice,
stock: item.Stock,
stockBracket: item.StockBracket,
sellPrice: item.SellPrice,
demand: item.Demand,
demandBracket: item.DemandBracket,
})),
commodities: commodityData,
},
};

Expand Down

0 comments on commit b98ef22

Please sign in to comment.