Leaner Battle data
This blog will explain a minor patch for the repository that I am going to release.
In a previous patch, I've removed gold
property from cards which reduced the storage by 10 percent. Then I started thinking, what else can I chop off my older data.
Old Battle-data | New, Lean Battle-data |
---|---|
Card stats as an object | Now they are in array entries, which can be turned to object easily with Object.entries([entries]) |
removed inactive, match_type | inactive matches will assert constraints on card options, not the cards themselves. & match_type won't affect the outcome('I hope So!!!) |
![]() | ![]() |
~26 MB size | ~11 MB size (only half) |
Code differences
replaced 'fs' with 'jsonfile', and node-fetch with async-get-json. Since we will handle only JSON files, I didn't like to handle the JSON parsing and stringing during operations. So getBattleHistory
changed, but slightly.
extracting cards from teams has improved since we are capturing id and level as arrays. To that effect, removed cleanBattles, extractbattleinfo, extractmonsters, and replaced them with one function.
const __medusa=(m)=>(m.card_detail_id==194&&m.level<3)?17:m.card_detail_id; // medusa and elven mistress are same cards
const xtractTeam=(t)=>[...[t.summoner,...t.monsters].map(m=>[__medusa(m),m.level])]
Proxy to the winner
I learnt a new concept clled proxy.
const winner = 'somePlayer';
const won = new Proxy({winner},{get: (t,p,r)=>{//target,prop,reciever
if(t.winner=='d'){return 'd'}
return t.winner==p?'w':'l';
}});
I created a proxy object which will take the winner, and return the verdict of the match from the target's perspective. If the player is not the winner, it will return 'l' for lost or draw, if the result was 'DRAW'. I could have used a normal tertiary statement. But when I read about this concept, I used it so I will understand it.
Next patch
By the next patch, I would completely try to use the above data for scores and elsewhere. So, my script will change in the future. I currently saved the above script as a new file in my repo.