summaryrefslogtreecommitdiff
path: root/public/js/mv/parse.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js/mv/parse.js')
-rw-r--r--public/js/mv/parse.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/public/js/mv/parse.js b/public/js/mv/parse.js
index 8094bc5..f8c1fd7 100644
--- a/public/js/mv/parse.js
+++ b/public/js/mv/parse.js
@@ -1,7 +1,16 @@
var mv = function(mv) {
mv.parser = function() {
var parser = {};
+ /* The most recent information of a pc's stat */
var pcstat = {};
+ /*
+ * The first recorded state of a pc's stat.
+ * This is saved for a second pass, in which instances unknown at the time can have the pc's stat applied.
+ */
+ var firstpcstat = {};
+ /*
+ * The time stamp of the last unknown instance.
+ */
var fullyDefinedCutoff = 0;
parser.records = [];
parser.fullyDefinedCutoff = function() { return fullyDefinedCutoff; };
@@ -93,16 +102,73 @@ var mv = function(mv) {
s.int = Math.floor(s.int / 10);
s.dex = Math.floor(s.dex / 10);
s.luk = Math.floor(s.luk / 10);
+ if (!(d[1] in firstpcstat)) {
+ firstpcstat = s;
+ }
pcstat[d[1]] = s;
return;
}
});
};
+ parser.postProcessing = function() {
+ /* Scrub reference to pc id, and scan up until the fully defined cutoff line, assigning the pcstat from those that logged off */
+ var i = 0;
+ /* This name has way too many warts; suggestions for a replacement welcome! */
+ var postProcessedfullyDefinedCutoff = 0;
+ for (; i != parser.records.length && parser.records[i].date <= fullyDefinedCutoff; ++i) {
+ /* See if we've found out what the stats were from information logged after the record. */
+ if (parser.records[i].pc in firstpcstat) {
+ parser.records[i].pcstat = firstpcstat[parser.records[i].pc];
+ } else {
+ /* If not, adjust the fully defined cutoff. */
+ postProcessedfullyDefinedCutoff = parser.records[i].date;
+ }
+ /* Remove references to pc from these records. */
+ delete parser.records[i].pc;
+ }
+ /* Remove references to pc from the remaining records. */
+ for (; i != parser.records.length; ++i) {
+ delete parser.records[i].pc;
+ }
+ fullyDefinedCutoff = postProcessedfullyDefinedCutoff;
+ }
function softAssert(expr, msg) {
if (!expr) {
console.error("SOFTASSERT FAILURE: " + msg);
}
}
+ parser.createBlobLink = function() {
+ /* Make the scrubbed data available for download as a blob. */
+ var blob = new Blob(JSON.stringify(parser.records));
+ var a = d3.select('body').append('a');
+ a
+ .text("Scrubbed records")
+ .attr("download", "map.scrubbed")
+ .attr("href", window.URL.createObjectURL(blob))
+ ;
+ }
+ parser.parseScrubbed = function(scrubbedRecords) {
+ scrubbedRecords = JSON.parse(scrubbedRecords);
+ console.log(scrubbedRecords, scrubbedRecords.length);
+ /*
+ * The work is mostly all done for us. Just scan through to see if there
+ * are any undefined records, and update the pointer if so.
+ */
+ /*
+ * Note that because we do not have the IDs, we cannot do a second pass
+ * to see if there is any information outside of the file that would
+ * tell us what the stats are, because we do not have that information.
+ * We can only get as good as what we were given!
+ */
+ for (var i = 0; i != scrubbedRecords.length; ++i) {
+ scrubbedRecords[i].date = new Date(scrubbedRecords[i].date);
+ if (scrubbedRecords[i].pcstat == undefined && (!fullyDefinedCutoff || scrubbedRecords[i].date > fullyDefinedCutoff)) {
+ fullyDefinedCutoff = scrubbedRecords[i].date;
+ }
+ }
+ /* It's simple when everything's already been done. */
+ parser.records = parser.records.concat(scrubbedRecords);
+ }
return parser;
}();
return mv;