Skip to content

Commit

Permalink
fix: Improve Sentient Outpost Data (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Mar 2, 2020
1 parent 4b86823 commit 79047e3
Show file tree
Hide file tree
Showing 18 changed files with 611 additions and 172 deletions.
17 changes: 17 additions & 0 deletions .github/update_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
setup_git() {
git config --global user.email "travis@travis-ci.com"
git config --global user.name "Travis CI"
git remote set-url origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
git checkout master
}

publish_docs() {
git add docs/.
git commit --message "chore(automated): Docs Update ${TRAVIS_BUILD_NUMBER} [ci skip]"
git push origin master
}

setup_git
npm run build-docs
publish_docs
37 changes: 22 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
os: linux
cache:
directories:
- ~/.npm
Expand All @@ -12,20 +13,18 @@ node_js:
- "lts/*"
- node

before_script:
- greenkeeper-lockfile-update

after_script: greenkeeper-lockfile-upload

branches:
except:
- /^v\d+\.\d+\.\d+$/
install: npm install

stages:
- lint
- test
- coverage
- release
- name: lint
- name: test
- name: coverage
- name: greenkeeper
if: branch =~ /^greenkeeper.*$/
- name: release
if: branch = master && type NOT IN (pull_request)
- name: docs
if: branch = master && type NOT IN (pull_request)

jobs:
include:
Expand All @@ -35,12 +34,20 @@ jobs:
script: npm test
- stage: coverage
script: npm run coverage
- stage: greenkeeper
before_install: npm i -g greenkeeper-lockfile
install: npm i
script:
- greenkeeper-lockfile-update
- greenkeeper-lockfile-upload
- stage: release
node_js: node
deploy:
provider: script
skip_cleanup: true
cleanup: false
script:
- npx semantic-release

install: npm install
- stage: docs
script:
- chmod +x ./.github/update_docs.sh
- ./.github/update_docs.sh
10 changes: 5 additions & 5 deletions jsdoc-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
"monospaceLinks": false,
"systemName" : "warframe-worldstate-parser",
"footer" : "",
"copyright" : "",
"includeDate" : false,
"copyright" : "©2020, WFCD",
"includeDate" : true,
"navType" : "vertical",
"theme" : "cosmo",
"linenums" : false,
"collapseSymbols" : false,
"linenums" : true,
"collapseSymbols" : true,
"inverseNav" : true,
"outputSourceFiles" : true,
"outputSourcePath" : true,
"dateFormat" : "dddd, MMMM Do YYYY, HH:mm:ss",
"syntaxTheme" : "default",
"syntaxTheme" : "dark",
"sort" : "longname, version, since",
"search" : true
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Invasion.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Invasion extends WorldstateObject {
* Whether this invasion is against the infestation
* @type {boolean}
*/
this.vsInfestation = /infest/i.test(this.attackingFaction);
this.vsInfestation = /infest/i.test(data.DefenderMissionInfo.faction);

/**
* The time at which the invasion starts
Expand Down
88 changes: 64 additions & 24 deletions lib/Kuva.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,55 @@
'use strict';

const Cache = require('json-fetch-cache');
/**
* Truncate time for a semlar-provided mission
* @param {Object} mission parsed mission with re-aligned field names
*/
const truncateTime = (mission) => {
mission.expiry.setHours(mission.activation.getHours() + 1);
mission.expiry.setMinutes(4);
mission.expiry.setSeconds(0);
mission.expiry.setMilliseconds(0);
mission.activation.setMinutes(mission.activation.getMinutes() + 5.1);
};

const parse = (data, translator, locale) => {
const parsed = {
kuva: [],
arbitration: {},
};
/**
* Scrub unnecessary details from the mission
* @param {Object} mission parsed mission with re-aligned field names
*/
const scrub = (mission) => {
/* eslint-disable no-param-reassign */
delete mission.solnode;
delete mission.name;
delete mission.node_type;
delete mission.tile;
delete mission.planet;
/* eslint-enable no-param-reassign */
};

/**
* Parse kuva & arbitration data
* @param {Object} data Data to split for kuva/arbitration
* @param {Object.<function>} translator Translator functions
* @param {string} locale locale to translate
* @returns {Object} Split parsed data
*/
const parse = (data, translator, locale) => {
const parsed = { kuva: [], arbitration: {} };
const now = new Date();

data.forEach((mission) => {
const p = {
activation: new Date(mission.start),
expiry: new Date(mission.end),
solnode: mission.solnode,
node: `${mission.solnodedata.tile} (${mission.solnodedata.planet})`,
...mission.solnodedata,
node: translator.node(mission.solnode, locale),
type: translator.nodeMissionType(mission.solnode, locale),
};
p.activation.setMinutes(p.activation.getMinutes() + 5.1);
truncateTime(p);
if (p.activation < now && now < p.expiry) {
if (mission.missiontype === 'EliteAlertMission') {
parsed.arbitration = p;
}
if (mission.missiontype.startsWith('KuvaMission')) {
parsed.kuva.push(p);
}
if (mission.missiontype === 'EliteAlertMission') parsed.arbitration = p;
if (mission.missiontype.startsWith('KuvaMission')) parsed.kuva.push(p);
}
scrub(p);
});

return parsed;
Expand Down Expand Up @@ -57,14 +79,32 @@ const parse = (data, translator, locale) => {
* @property {ExternalMission} arbitration current arbitration
*/
class Kuva {
constructor({ kuvaCache, translator, locale }) {
this.cache = kuvaCache || new Cache('https://10o.io/kuvalog.json', 300000, { useEmitter: false, delayStart: true, maxRetry: 5 });
this.cache.getData()
.then((data) => {
const parsed = parse(data, translator, locale);
this.kuva = parsed.kuva;
this.arbitration = parsed.arbitration;
});
constructor({
kuvaData, translator, locale, logger,
}) {
/**
* The translation functions
* @type {Translator}
* @private
*/
this.translator = translator;
Object.defineProperty(this, 'translator', { enumerable: false, configurable: false });

/**
* The locale to leverage for translations
* @type {string}
* @private
*/
this.locale = locale;
Object.defineProperty(this, 'locale', { enumerable: false, configurable: false });

if (!kuvaData) {
// eslint-ignore-next-line no-console
logger.debug('No defined kuva data, skipping data');
} else {
const parsed = parse(kuvaData, this.translator, this.locale);
({ kuva: this.kuva, arbitration: this.arbitration } = parsed);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/News.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class News extends WorldstateObject {
}

/**
* The title of the new in the specified language
* The title of the news item in the specified language
* @param {string} langCode Ex. 'es', 'de', 'fr'
* @returns {string}
*/
Expand Down
29 changes: 27 additions & 2 deletions lib/SentientOutpost.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const approxDuration = 1800;

const sat = () => {
const now = Math.floor(Date.now() / 1000);
// One cycle = 3 hours
Expand All @@ -26,10 +28,21 @@ const sat = () => {

/**
* Represents a set of sentient outposts that are present
* @property {Mission[]} missions List of current missions
* Parsed source is combined data from DE's worldstate and semlar.com/anomaly.json
* @property {Mission} mission List of current missions
* @property {string} id Identifier for the mission node with active indicator
* @property {boolean} active Whether or not the mission is active
* @property {Date} activation When the mission became or becomes active
* @property {Date} expiry When the mission became or becomes inactive
* @property {Object} previous Estimation data for the last mission that was active.
* Could also be the current.
* @property {Date} previous.activation When the mission became or becomes active
* @property {Date} previous.expiry When the mission became or becomes inactive
*/
class SentientOutpost {
constructor(data = '{\\"sfn\\":000}', { translator, locale }) {
constructor(data = '{\\"sfn\\":000}', {
translator, locale, sentientData, logger,
}) {
const node = (data.match(/\d{3}/g) || ['000'])[0];
const id = `CrewBattleNode${node}`;
if (node === '000') {
Expand All @@ -44,6 +57,18 @@ class SentientOutpost {
({ activation: this.activation, expiry: this.expiry } = sat());
this.active = this.mission !== null;
this.id = `${id}:${this.active}`;

if (!sentientData) {
logger.debug('No outpost data, skipping');
} else {
this.previous = {
activation: new Date(sentientData.start * 1000),
expiry: new Date(sentientData.end * 1000),
};

this.activation = new Date(sentientData.projection * 1000);
this.expiry = new Date((sentientData.projection + approxDuration) * 1000);
}
}
}

Expand Down
17 changes: 6 additions & 11 deletions lib/WorldState.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const safeObj = (obj) => (obj || {});
* @property {Mission} Mission The Mission parser
* @property {Reward} Reward The Reward parser
* @property {string} locale Locale to use for translations
* @property {object} logger Generic logger to use if needed
*/

/**
Expand All @@ -88,12 +89,13 @@ const defaultDeps = {
Simaris,
ConclaveChallenge,
PersistentEnemy,
WeeklyChallenge,
timeDate,
translator,
sortieData,
mdConfig,
locale: 'en',
WeeklyChallenge,
logger: console,
};

function parseArray(ParserClass, dataArray, deps, uniqueField) {
Expand Down Expand Up @@ -288,23 +290,16 @@ class WorldState {
// kuva & arbies
this.externalMissions = new Kuva(deps);
Object.defineProperty(this, 'externalMissions', { enumerable: false, configurable: false });
setTimeout((self) => {
/* eslint-disable no-param-reassign */
self.kuva = this.externalMissions.kuva;
self.arbitration = this.externalMissions.arbitration;
/* eslint-enable no-param-reassign */
}, 1000, this);

// after removing cache, this is immediately available
({ kuva: this.kuva, arbitration: this.arbitration } = this.externalMissions);

/**
* Current syndicate outposts
* @type {SyndicateOutpost}
*/
this.sentientOutposts = new SyndicateOutpost(data.Tmp, deps);
}

stopKuva() {
this.externalMissions.cache.stopUpdating();
}
}

module.exports = WorldState;
Loading

0 comments on commit 79047e3

Please sign in to comment.