ιχθυσς (ichthuss) wrote,
ιχθυσς
ichthuss

Знічев'я намалював скрипт-букмарклет для оцінки американських опитувань по індексу, запропонованому stzozo. Приклад роботи:

StateRepDemVotersData
DC23.5276.483Old
Vermont28.5771.433New
...
Minnesota46.9153.0910New
Ohio47.6752.3318New
Oregon48.1951.817New
...
Idaho65.6734.334New
Wyoming70.4929.513Old


Цифри республіканців / демократів у виділеній жирним строчці і є значеннями індексу.



Для використання потрібно:

1. Створити в браузері закладку з кодом: [URI]
javascript:(function(){$.getJSON('http://www.270towin.com/2016-polls-clinton-trump/php/process.php',{},function(json){p=$('#pies');p.empty();var ro=json.results;var or=[["Alaska",0.375,3],["Alabama",0.3890,9],["Arkansas",0.4393,6],["Arizona",0.4528,11],["California",0.6172,55],["Colorado",0.5504,9],["Connecticut",0.5296,7],["DC",0.7648,3],["Delaware",0.5303,3],["Florida",0.5029,29],["Georgia",0.5059,16],["Hawaii",0.6192,4],["Iowa",0.5,6],["Idaho",0.4300,4],["Illinois",0.5779,20],["Indiana",0.4492,11],["Kansas",0.4342,6],["Kentucky",0.4140,8],["Louisiana",0.3935,8],["Massachusetts",0.5992,11],["Maryland",0.6090,10],["Maine",0.4874,4],["Michigan",0.5160,16],["Minnesota",0.5610,10],["Missouri",0.4474,10],["Mississippi",0.3938,6],["Montana",0.4414,3],["North Carolina",0.4820,15],["North Dakota",0.4461,3],["Nebraska",0.4253,5],["New Hampshire",0.5048,4],["New Jersey",0.5585,14],["New Mexico",0.5175,5],["Nevada",0.5234,6],["New York",0.6016,29],["Ohio",0.4951,18],["Oklahoma",0.4144,7],["Oregon",0.5540,7],["Pennsylvania",0.5023,20],["Rhode Island",0.5698,4],["South Carolina",0.4420,9],["South Dakota",0.4096,3],["Tennessee",0.4053,11],["Texas",0.4675,38],["Utah",0.4263,6],["Virginia",0.5284,13],["Vermont",0.6017,3],["Washington",0.5847,12],["Wisconsin",0.5123,10],["West Virginia",0.3337,5],["Wyoming",0.2951,3]]
;var i;for (i=0;i<or.length;i++){if(ro[or[i][0]]==undefined)ro[or[i][0]]={poll_rep:1-or[i][1],poll_dem:or[i][1],old:1};else{ro[or[i][0]].old=0};ro[or[i][0]].voters=or[i][2]};var r=[];for (var d in ro){if (d!=0) r.push({name:d,rep:ro[d].poll_rep/(ro[d].poll_rep+ro[d].poll_dem),dem:ro[d].poll_dem/(ro[d].poll_rep+ro[d].poll_dem),old:ro[d].old,voters:ro[d].voters});};r.sort(function(a,b){return a.rep-a.dem-b.rep+b.dem;});var sv=0;for(i=0;i<r.length;i++) if (r[i].voters>0)sv+=+r[i].voters;var clr=["e0e0ff","e0ffe0","ffe0e0"];var t=$('<table>');var sv2=0;var flag=0;var tr=$('<tr>').css('background-color','#c0c0c0').css('font-weight','bold');t.append(tr);$.each(["State","Rep","Dem","Voters","Data"],function(k,v){var td=$('<td>').html(v);tr.append(td);});for(i=0;i<r.length;i++) {if (r[i].voters>0)sv2+=+(r[i].voters);if((sv2*2>sv)&flag<2){flag++};var tr=$('<tr>').css('background-color','#'+clr[flag]);if(flag==1)tr.css('font-weight','bold');t.append(tr);var rw=[r[i].name,Math.round(r[i].rep*10000)/100,Math.round(r[i].dem*10000)/100,r[i].voters,r[i].old?"<font color=red>Old</fond>":"New"];$.each(rw,function(k,v){var td=$('<td>').html(v);tr.append(td);});p.append(t);}});})();


2. Перейти на сторінку http://www.270towin.com/2016-polls-clinton-trump/ .

3. Натиснути на закладку.

Теоретично повинно працювати у всіх браузерах; перевірено на файерфоксі.
Tags: політика, поточне
Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 10 comments