if(data.assembly_state_tally_Details && data.assembly_state_tally_Details.result && data.assembly_state_tally_Details.result.length > 0){ //console.log(data.assembly_state_tally_Details.result) data.assembly_state_tally_Details.result.forEach((item) => { const stateName = lang ? data.assembly_state_tally_Details.stateData['state_'+item.state_id][lang+'_state'] : item.statename; const seatsum = item.seats.reduce((a, b) => parseInt(a) + parseInt(b), 0); const getTallyShareData = getTallyShare(data, item); item.statename.toLowerCase().replace(' ','-') var assembly_election_url = item.statename.toLowerCase().replace(' ','-')+'-assembly-election-2023.html'; // var assembly_election_url = assembly_election_url""; var complete_state_url = (_isNeed == 'true')?"https://www.abplive.com/"+'elections/'+assembly_election_url:'javascript:void(0);'; var _idMizo = (_mizo == 'true')?item.statename.toLowerCase().replace(' ','-')+"-el23":''; //console.log("tally", getTallyShareData) mainTallyHtml += `
${seatsum}/${item.totalseat}
` }); mainTallyHtml+=`${tallyColor}`; mainTallyHtml += `
${Math.floor(item.totalseat/2)+1} to win
`; }) mainTallyHtml += `${alliaceName}
`; if(languageArray.includes(lang)){ mainTallyHtml += `Full Result Tally `; } mainTallyHtml += `
`; }) }
return mainTallyHtml }
function getTallyShare(data, result){ //console.log(data, result) const arr = []; let leftwining = 0 result.alliace.forEach((i, index) => { let wining_percentage = ((result.seats[index]*100)/result.totalseat).toFixed(1); if(index > 0){ leftwining += +((result.seats[index - 1] / result.totalseat) * 100).toFixed(1) } arr.push({ party_id:i, party_color:data.assembly_state_tally_Details.partyData['party_'+result.alliace[index]]['color_code'], party_seat:result.seats[index], party_name:result.alliace_name[index], total_seat:result.totalseat, wining_percentage:wining_percentage+"%", leftwining:leftwining == 0 ? leftwining : leftwining+"%" }) console.log(wining_percentage, leftwining); //leftwining = leftwining+ + +wining_percentage;
}) return arr; } setInterval(()=>{ //document.querySelector("#e23-main-tally-inner").innerHTML = ''; getOpinionData(); },45000)
function resetBudgetTicker(){ $('#election-breaking-news').flipbox({ vertical: true, autoplay: true, autoplayReverse: false, autoplayWaitDuration: 5000, autoplayPauseOnHover: true }); }
window.addEventListener('DOMContentLoaded', (event) => { resetBudgetTicker(); });
//JS PART CODE for LIVE var budgetBreakingFile = "PRE_BREAKING_NEWS_FEEDS_URLhome/index";
// var trigger_web_budget=setInterval(function(){ // // console.log(budgetBreakingFile); // get_budget_live(budgetBreakingFile) // }, 45000);
function get_budget_live(budgetBreakingFile){ fetch(budgetBreakingFile) .then((response) => response.json()) .then((budgetBreaking) => { var sliderLiveMidContent = ''; //Code Start if(budgetBreaking && budgetBreaking['breaking_news'].length > 0){ budgetBreaking['breaking_news'].forEach(element => { if(element.title.length > 0){ if(element.link){ sliderLiveMidContent+= ''+ element.title +''; }else{ sliderLiveMidContent+= '
'; } } }); $('#election-breaking-news').flipbox('destroy'); document.querySelector("#election-breaking-news").innerHTML = sliderLiveMidContent; resetBudgetTicker(); } }) .catch((error) => { console.error('Error:', error); }); }
// var trigger_web_budget=setInterval(function(){ // // get_candidate_live(keyCandidateFile,keyCandidateFile1) // }, 45000);
var _prState = ["up","pb","uk","ga","mn","guj","hp","ml","tr","nl","ka","up-nikay","mp","mizo","ch","raj","tel"]; function groupBy(objectArray, property) {
return objectArray.reduce((acc, obj) => { const key = obj[property]; const newArr = []; if (!acc[key]) { acc[key] = []; } // Add object to list for given key's value acc[key].push(obj); return acc; }, {}); } function _splitArrayIntoChunksOfLen(arr, len) { var chunks = [], i = 0, n = arr.length; while (i < n) { chunks.push(arr.slice(i, i += len)); } return chunks; } const mergeDedupe = (arr) => { return [...new Set([].concat(...arr))]; }
function getMultipleRandom(arr, num) { const shuffled = [...arr].sort(() => 0.5 - Math.random()); return shuffled.slice(0, num); }
function get_candidate_live(keyCandidateFile,keyCandidateFile1=false){ Promise.all([ fetch(keyCandidateFile).then( (response) => response.json()), fetch(keyCandidateFile1).then( (response) => response.json()) ]) .then((candidates) => { candidates = mergeDedupe(candidates);
candidates = getMultipleRandom(candidates, 20); var html =''; candidatesGroup = groupBy(candidates,'cstate'); _prState.forEach((_s) => {
if(typeof candidatesGroup[_s.toUpperCase()] !== 'undefined'){ let _d = _splitArrayIntoChunksOfLen(candidatesGroup[_s.toUpperCase()],5); for (const key in _d) {
_d[key].forEach((item) => {
var leadLower = item.c_leadwon != undefined || item.c_leadwon !== ''? item.c_leadwon.toLowerCase() : item.c_leadwon;
var cand_name = item.c_name ; var const_name = item.c_consti ;
if(cand_name == ''){ var cand_name = item.english_cname ; }
if(const_name == ''){ var const_name = item.c_english_consti ; }
html += '
'; }); } } }) document.querySelector(".keyCandidateSlider").innerHTML = html; }) .catch((error) => { console.error('Error:', error); }); }