From 9d3c8c0e6e1a7ba43bf3dc19350d1dca68b657a3 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sun, 10 Feb 2019 11:16:07 +0800 Subject: Initial commit. --- blog/data/applefan.json | 526 ++++++++++++++++++++++++++++++++++++++++++++++++ blog/data/poll.js | 171 ++++++++++++++++ 2 files changed, 697 insertions(+) create mode 100644 blog/data/applefan.json create mode 100644 blog/data/poll.js (limited to 'blog/data') diff --git a/blog/data/applefan.json b/blog/data/applefan.json new file mode 100644 index 0000000..e8e09f9 --- /dev/null +++ b/blog/data/applefan.json @@ -0,0 +1,526 @@ +{ + "title":"Are you an Apple fanboy/fangirl?", + "question":[ + { + "initialization":[ + { + "c":"", + "s":"have_ios = + 0" + }, + { + "c":"", + "s":"have_iph = + 0" + }, + { + "c":"", + "s":"airpods_sane = + 0" + } + ], + "precond":"", + "type":"multi", + "caption":"I have an/a...", + "choice":[ + { + "caption":"iPod (original/Photo/Classic)/iPod mini/iPod Nano (1G~5G)/iPod Shuffle", + "setp":[ + { + "c":"", + "s":"score = + score + 1" + } + ], + "setn":[] + }, + { + "caption":"iPod Nano (6G, 7G)/iPod touch", + "setp":[ + { + "c":"", + "s":"score = + score + 1.5" + } + ], + "setn":[] + }, + { + "caption":"iPhone", + "setp":[ + { + "c":"", + "s":"score = + score + 1.5" + }, + { + "c":"", + "s":"have_ios = + 1" + }, + { + "c":"", + "s":"have_iph = + 1" + } + ], + "setn":[] + }, + { + "caption":"iPhone X", + "setp":[ + { + "c":"| have_iph gt 0", + "s":"score = + score + 2" + }, + { + "c":"| have_iph lt 1", + "s":"score = + score + 3.5" + }, + { + "c":"", + "s":"have_ios = + 1" + } + ], + "setn":[] + }, + { + "caption":"iPad original/Mini/Air", + "setp":[ + { + "c":"", + "s":"score = + score + 2" + }, + { + "c":"", + "s":"have_ios = + 1" + } + ], + "setn":[] + }, + { + "caption":"iPad Pro", + "setp":[ + { + "c":"", + "s":"score = + score + 2.5" + }, + { + "c":"", + "s":"have_ios = + 1" + } + ], + "setn":[] + }, + { + "caption":"Apple Watch", + "setp":[ + { + "c":"| have_ios gt 0", + "s":"score = + score + 5" + }, + { + "c":"| have_ios lt 1", + "s":"score = + score + 105" + }, + { + "c":"", + "s":"airpods_sane = + 1" + } + ], + "setn":[] + }, + { + "caption":"Macintosh before 1998", + "setp":[ + { + "c":"", + "s":"score = + score - 2" + } + ], + "setn":[] + }, + { + "caption":"PowerBook or Power Mac", + "setp":[ + { + "c":"", + "s":"score = + score + 0" + } + ], + "setn":[] + }, + { + "caption":"MacBook", + "setp":[ + { + "c":"", + "s":"score = + score + 2" + }, + { + "c":"", + "s":"airpods_sane = + 1" + } + ], + "setn":[] + }, + { + "caption":"MacBook Air/Pro", + "setp":[ + { + "c":"", + "s":"score = + score + 1.5" + }, + { + "c":"", + "s":"airpods_sane = + 1" + } + ], + "setn":[] + }, + { + "caption":"iMac", + "setp":[ + { + "c":"", + "s":"score = + score + 2" + }, + { + "c":"", + "s":"airpods_sane = + 1" + } + ], + "setn":[] + }, + { + "caption":"Mac Pro", + "setp":[ + { + "c":"", + "s":"score = + score + 2.5" + }, + { + "c":"", + "s":"airpods_sane = + 1" + } + ], + "setn":[] + }, + { + "caption":"Air Pods", + "setp":[ + { + "c":"| airpods_sane gt 0", + "s":"score = + score + 10" + }, + { + "c":"| airpods_sane lt 1", + "s":"score = + score + 110" + } + ], + "setn":[] + }, + { + "caption":"HomePod", + "setp":[ + { + "c":"| have_ios gt 0", + "s":"score = + score + 7" + }, + { + "c":"| have_ios lt 1", + "s":"score = + score + 107" + } + ], + "setn":[] + } + ] + }, + { + "initialization":[], + "precond":"", + "type":"single", + "caption":"I use Apple products because I am so dumb that I don't know how to use products from other vendors", + "choice":[ + { + "caption":"yes", + "setp":[ + { + "c":"", + "s":"score = + score - 10" + } + ], + "setn":[] + }, + { + "caption":"no", + "setp":[ + { + "c":"", + "s":"score = + score + 0" + } + ], + "setn":[] + } + ] + }, + { + "initialization":[], + "precond":"", + "type":"single", + "caption":"I use Apple products because they are far more superior than any other vendors' products", + "choice":[ + { + "caption":"yes", + "setp":[ + { + "c":"", + "s":"score = + score + 8" + } + ], + "setn":[] + }, + { + "caption":"no", + "setp":[ + { + "c":"", + "s":"score = + score + 0" + } + ], + "setn":[] + } + ] + }, + { + "initialization":[], + "precond":"", + "type":"single", + "caption":"I think Apple's products are worth all that money", + "choice":[ + { + "caption":"yes", + "setp":[ + { + "c":"", + "s":"score = + score + 5" + } + ], + "setn":[] + }, + { + "caption":"no", + "setp":[ + { + "c":"", + "s":"score = + score - 1" + } + ], + "setn":[] + } + ] + }, + { + "initialization":[], + "precond":"", + "type":"single", + "caption":"Apple products suck, I have to use them for my work however", + "choice":[ + { + "caption":"yes", + "setp":[ + { + "c":"", + "s":"score = + score - 7.5" + } + ], + "setn":[] + }, + { + "caption":"no", + "setp":[ + { + "c":"", + "s":"score = + score + 0" + } + ], + "setn":[] + } + ] + }, + { + "initialization":[], + "precond":"", + "type":"single", + "caption":"I think Apple respects my freedom and privacy", + "choice":[ + { + "caption":"yes", + "setp":[ + { + "c":"", + "s":"score = + score + 10" + } + ], + "setn":[] + }, + { + "caption":"no", + "setp":[ + { + "c":"", + "s":"score = + score - 2" + } + ], + "setn":[] + } + ] + }, + { + "initialization":[], + "precond":"", + "type":"single", + "caption":"I bought refurbished Apple products because...", + "choice":[ + { + "caption":"I can't afford a normal Apple product but I really want one", + "setp":[ + { + "c":"", + "s":"score = + score + 2" + } + ], + "setn":[] + }, + { + "caption":"Finally there's an Apple product that falls into my affordable range. I took it into consideration.", + "setp":[ + { + "c":"", + "s":"score = + score - 2" + } + ], + "setn":[] + }, + { + "caption":"I do not.", + "setp":[ + { + "c":"", + "s":"score = + score + 0" + } + ], + "setn":[] + } + ] + }, + { + "initialization":[], + "precond":"", + "type":"single", + "caption":"Keyboard on a MacBook (late 2016 and onward) is reliable and satisfying", + "choice":[ + { + "caption":"yes", + "setp":[ + { + "c":"", + "s":"score = + score + 1" + } + ], + "setn":[] + }, + { + "caption":"no", + "setp":[ + { + "c":"", + "s":"score = + score - 1" + } + ], + "setn":[] + }, + { + "caption":"I've never tried that", + "setp":[ + { + "c":"", + "s":"score = + score + 0" + } + ], + "setn":[] + } + ] + }, + { + "initialization":[], + "precond":"", + "type":"single", + "caption":"I think that Apple products are more secure and resistant to malware attacks.", + "choice":[ + { + "caption":"yes", + "setp":[ + { + "c":"", + "s":"score = + score + 2" + } + ], + "setn":[] + }, + { + "caption":"no", + "setp":[ + { + "c":"", + "s":"score = + score - 2" + } + ], + "setn":[] + } + ] + }, + { + "initialization":[], + "precond":"", + "type":"single", + "caption":"I am an Apple fanboy/fangirl.", + "choice":[ + { + "caption":"yes", + "setp":[ + { + "c":"", + "s":"score = + score + 1" + } + ], + "setn":[] + }, + { + "caption":"no", + "setp":[ + { + "c":"", + "s":"score = + score - 1" + } + ], + "setn":[] + } + ] + } + ], + "verdict":[ + { + "caption":"

Apple Hater.

This world needs more sanity like you.

", + "precond":"| score lt -4" + }, + { + "caption":"

What Apple?

Just stay this way.

", + "precond":"| score geq -4 & score lt 4" + }, + { + "caption":"

Apple Adorer.

No.

", + "precond":"| score geq 4 & score lt 7" + }, + { + "caption":"

Apple Fan.

Stop it. Get some help.

https://youtu.be/fkkDvKGcNSo?t=1081

", + "precond":"| score geq 7 & score lt 20" + }, + { + "caption":"

Incurable Apple Fan.

Fuck off. Nothing will help.

", + "precond":"| score geq 20" + } + ] +} diff --git a/blog/data/poll.js b/blog/data/poll.js new file mode 100644 index 0000000..55b4e22 --- /dev/null +++ b/blog/data/poll.js @@ -0,0 +1,171 @@ +//By Chris Xiong, 2018 +//License: Expat +let p=null; +let Caption; +let Choices; +let Score; +let Next; +let values=[]; +let curq; +function evalexpr(e) +{ + let ret=0; + let op=function(a,o,b){ + switch(o){ + case '+':return a+b; + case '-':return a-b; + case '*':return a*b; + case '/':return a/b; + } + }; + for(let p=e.match(/[+\-*\/]/);p;p=e.match(/[+\-*\/]/)) + { + let vp=e.match(/[A-Za-z]\w*/); + if(vp) + { + const v=vp[0]; + if(values[v]===undefined)throw 'shit'; + ret=op(ret,p[0],values[v]); + e=e.substr(vp.index+vp[0].length); + } + else + { + let np=e.match(/\d+(.\d*)?/); + if(np) + { + const n=Number(np[0]); + ret=op(ret,p[0],n); + e=e.substr(np.index+np[0].length); + }else throw 'shit'; + } + } + return ret; +} +function evalsetexpr(e) +{ + const s=e.split('='); + if(s.length<2)throw 'shit'; + values[s[0].trim()]=evalexpr(s[1]); +} +function evaltestexpr(e) +{ + const m=e.match(/([A-Za-z]\w*)\s*(leq|geq|lt|gt)\s*([A-Za-z0-9.]*)/); + if(!m)throw 'shit'; + const v=m[1],op=m[2],vr=m[3]; + const vv=values[v]; + const vvr=isNaN(Number(vr))?values[vr]:Number(vr); + if(vv===undefined||vvr===undefined)throw 'shit'; + switch(op.trim()) + { + case 'leq':return vv<=vvr; + case 'geq':return vv>=vvr; + case 'lt':return vvvvr; + } + throw 'shit'; +} +function evalcondexpr(e) +{ + if(!e.trim().length)return true; + let ret=false; + let op=function(a,o,b){ + switch(o){ + case '|':return a||b; + case '&':return a&&b; + } + }; + for(let p=e.search(/[|&]/);p!=-1;p=e.search(/[|&]/)) + { + let np=e.substr(p+1).search(/[|&]/); + let n=e.substr(p+1,np!=-1?np-1:undefined); + ret=op(ret,e[p],evaltestexpr(n.trim())); + e=np?e.substr(np):""; + } + return ret; +} +function initq() +{ + const q=p.question[curq]; + for(let i=0;i=p.question.length)return; + const q=p.question[curq]; + let seln=0; + for(let i=0;i