-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66c3617
commit b08fae3
Showing
2 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
var label = {}; | ||
label['en'] = {}; | ||
label['es'] = {}; | ||
label['fr'] = {}; | ||
|
||
//IDs in index.html | ||
|
||
label["en"]["createdby"]="Created by"; | ||
label["es"]["createdby"]="Creado por"; | ||
|
||
label["en"]["input-account"]="Account"; | ||
label["es"]["input-account"]="Cuenta"; | ||
|
||
label["en"]["title-activity-account"]="Account activity"; | ||
label["es"]["title-activity-account"]="Actividad de la cuenta"; | ||
|
||
label["en"]["lastweeks"]="Last 4 weeks"; | ||
label["es"]["lastweeks"]="Últimas 4 semanas"; | ||
|
||
label["en"]["title-activity-followers"]="Account activity"; | ||
label["es"]["title-activity-followers"]="Actividad de los seguidores"; | ||
|
||
label["en"]["title-followers"]="Followers"; | ||
label["es"]["title-followers"]="Seguidores"; | ||
|
||
label["en"]["lastweeks2"]="Last 4 weeks"; | ||
label["es"]["lastweeks2"]="Últimas 4 semanas"; | ||
|
||
label["en"]["steemactivityby"]='Steem activity by <a href="https://steemit.com/@jga/">@jga</a>'; | ||
label["es"]["steemactivityby"]='Steem activity por <a href="https://steemit.com/@jga/">@jga</a>'; | ||
|
||
label["en"]["seeitongithub"]='See it on <a href="https://github.com/joticajulian/steem-activity/">github.com</a> and <a href="https://www.steem.center/index.php?title=Steem_Ecosystem:S-Steemis">steem.center</a>'; | ||
label["es"]["seeitongithub"]='Míralo en <a href="https://github.com/joticajulian/steem-activity/">github.com</a> y también en <a href="https://www.steem.center/index.php?title=Steem_Ecosystem:S-Steemis">steem.center</a>'; | ||
|
||
//labels in steem_activity.js | ||
|
||
label["en"]["Local time: "]="Local time: "; | ||
label["es"]["Local time: "]="Tiempo local: "; | ||
|
||
label["en"]["nameDay"]=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']; | ||
label["es"]["nameDay"]=['Domingo','Lunes','Martes','Miércoles','Jueves','Viernes','Sábado']; | ||
|
||
label["en"]["Followers of @"]="Followers of @"; | ||
label["es"]["Followers of @"]="Seguidores de @"; | ||
|
||
label["en"][" votes"]=" votes"; | ||
label["es"][" votes"]=" votos"; | ||
|
||
label["en"][". Complete"]=". Complete"; | ||
label["es"][". Complete"]=". Completo"; | ||
|
||
label["en"]["Best Time #"]="Best Time #"; | ||
label["es"]["Best Time #"]="Mejor tiempo #"; | ||
|
||
label["en"][" at "]=" at "; | ||
label["es"][" at "]=" a las "; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,274 @@ | ||
var language = navigator.language || navigator.userLanguage; | ||
load_language(); | ||
|
||
var now = new Date(); | ||
var gmt = now.getTimezoneOffset()*60*1000; //gmt in milliseconds | ||
var last1week = new Date(now.getFullYear(),now.getMonth(),now.getDate()-6); | ||
var last2week = new Date(now.getTime() - 2*7*24*60*60*1000); | ||
var last3week = new Date(now.getTime() - 3*7*24*60*60*1000); | ||
var last4week = new Date(now.getTime() - 4*7*24*60*60*1000); | ||
|
||
document.getElementById("timezone1").innerHTML = label[language]["Local time: "] + gmtToString(); | ||
document.getElementById("timezone2").innerHTML = label[language]["Local time: "] + gmtToString(); | ||
|
||
//Array of Votes and initialization | ||
var votesDay = [0,0,0,0,0,0,0]; | ||
var a_votesDay = [0,0,0,0,0,0,0]; | ||
|
||
var votes = new Array(7); | ||
for(i=0;i<7;i++){ | ||
votes[i] = new Array(24); | ||
for(j=0;j<24;j++){ | ||
votes[i][j]=0; | ||
} | ||
} | ||
|
||
var a_votes = new Array(7); | ||
for(i=0;i<7;i++){ | ||
a_votes[i] = new Array(24); | ||
for(j=0;j<24;j++){ | ||
a_votes[i][j]=0; | ||
} | ||
} | ||
|
||
var followersLoaded = 0; | ||
var totalFollowers = 0; | ||
var textFollowers = ""; | ||
nameDay = label[language]["nameDay"]; | ||
nameHours = ['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23']; | ||
|
||
|
||
var maxVotation = [0,0,0,0]; | ||
var maxVotationDay = 0; | ||
var bestHour = [[0,0],[0,0],[0,0],[0,0]]; | ||
var bestDay = 0; | ||
var refreshPlot = 10; | ||
var refreshText = 5; | ||
var firstPlot = true; | ||
var firstText = true; | ||
|
||
function loadFollowersActivity(){ | ||
steem.api.getConfig(function(err, response){ | ||
console.log(err, response); | ||
}); | ||
|
||
var account = getQuery(); | ||
|
||
steem.api.getAccounts([account], function(err, result){ | ||
console.log(err, result); | ||
var info = JSON.parse(result[0].json_metadata); | ||
if(info.profile.hasOwnProperty('profile_image')){ | ||
console.log(info.profile.profile_image + " extracted: " + extractUrlProfileImage(info.profile.profile_image)); | ||
document.getElementById("profile_image").src = extractUrlProfileImage(info.profile.profile_image); | ||
}else{ | ||
console.log("no photo"); | ||
} | ||
}); | ||
|
||
document.getElementById("labelAccount").innerHTML = "@" + account; | ||
document.getElementById("title-followers").innerHTML = label[language]["Followers of @"] + account; | ||
//document.getElementById("title-activity-account").innerHTML = "Activity of @" + account; | ||
|
||
consultVotesAccount(account); | ||
|
||
steem.api.getFollowCount(account, function(err,result) { | ||
console.log("Number of followers: "+result.follower_count); | ||
totalFollowers = result.follower_count; | ||
document.getElementById("title-followers").innerHTML = label[language]["Followers of @"] + account + ": "+totalFollowers; | ||
consultVotesFollowers(account,0); | ||
}); | ||
} | ||
|
||
function consultVotesAccount(account){ | ||
steem.api.getAccountVotes(account, function(err, result) { | ||
//console.log(err,result); | ||
//if (err) //error | ||
//look each vote and put it in the array regarding the time | ||
for(i=result.length-1;i>=0;i--){ | ||
var timeUTC = new Date(result[i].time); | ||
var time = new Date(timeUTC.getTime() - gmt); | ||
if(timeToBreak(time,result.length-i)) break; | ||
var hours = time.getHours(); | ||
var day = time.getDay(); | ||
a_votes[day][hours]++; | ||
a_votesDay[day]++; | ||
} | ||
|
||
for(i=0;i<7;i++){ | ||
var data = [{ | ||
x: nameHours, | ||
y: a_votes[i], | ||
type: 'bar' | ||
}]; | ||
var layout = { title: nameDay[i] }; | ||
Plotly.newPlot('a-chart'+i, data,layout); | ||
document.getElementById("a-votesDay"+i).innerHTML = nameDay[i]+": "+a_votesDay[i]+label[language][" votes"]; | ||
} | ||
}); | ||
} | ||
|
||
function consultVotesFollowers(account, fromFollower){ | ||
steem.api.getFollowers(account, fromFollower, 0, 21, function(err, result) { | ||
|
||
//look each for each Follower | ||
var finish = result.length-1; | ||
if(result.length == 1) finish=1; //last follower | ||
|
||
for(i=0;i<finish;i++){ | ||
if(result[i].what[0] != 'blog') continue; | ||
textFollowers = textFollowers + link(result[i].follower) + " . . . . "; | ||
|
||
steem.api.getAccountVotes(result[i].follower, function(err, result) { | ||
//if (err) //error | ||
//look each vote and put it in the array regarding the time | ||
for(i=result.length-1;i>=0;i--){ | ||
var timeUTC = new Date(result[i].time); | ||
var time = new Date(timeUTC.getTime() - gmt); | ||
if(timeToBreak(time,result.length-i)) break; | ||
var hours = time.getHours(); | ||
var day = time.getDay(); | ||
votes[day][hours]++; | ||
votesDay[day]++; | ||
for(j=0;j<4;j++){ | ||
if(votes[day][hours] > maxVotation[j]){ | ||
maxVotation[j] = votes[day][hours]; | ||
bestHour[j] = [day,hours]; | ||
break; | ||
} | ||
} | ||
if(votesDay[day] > maxVotationDay){ | ||
maxVotationDay = votesDay[day]; | ||
bestDay = day; | ||
} | ||
} | ||
|
||
followersLoaded++; | ||
|
||
refreshText--; | ||
if(firstText || refreshText==0 || followersLoaded==totalFollowers){ | ||
var percentage = 100*followersLoaded/totalFollowers; | ||
var tPer = percentage.toFixed(2); | ||
var tBar = followersLoaded + "/" + totalFollowers; | ||
if(followersLoaded == totalFollowers) tBar = tBar + label[language][". Complete"]; | ||
document.getElementById("progress-bar").innerHTML = tBar; | ||
document.getElementById("progress-bar").ariaValuenow = tPer; | ||
document.getElementById("progress-bar").style = "width: "+tPer+"%;"; | ||
document.getElementById("followers").innerHTML = textFollowers; | ||
for(i=0;i<4;i++){ | ||
document.getElementById("bestTime"+i).innerHTML = label[language]["Best Time #"]+(i+1)+": " + nameDay[bestHour[i][0]] + label[language][" at "] + bestHour[i][1] + " H"; | ||
} | ||
firstText = false; | ||
refreshText = 5; | ||
} | ||
|
||
refreshPlot--; | ||
if(firstPlot || refreshPlot==0 || followersLoaded==totalFollowers){ | ||
for(i=0;i<7;i++){ | ||
var data = [{ | ||
x: nameHours, | ||
y: votes[i], | ||
type: 'bar' | ||
}]; | ||
var layout = { title: nameDay[i] }; | ||
Plotly.newPlot('f-chart'+i, data,layout); | ||
document.getElementById("f-votesDay"+i).innerHTML = nameDay[i]+": "+votesDay[i]+label[language][" votes"]; | ||
} | ||
firstPlot = false; | ||
refreshPlot = 10; | ||
} | ||
}); | ||
} | ||
|
||
if(result.length>1){ | ||
var lastFollower = result[result.length-1].follower; | ||
console.log("Consult from "+lastFollower); | ||
consultVotesFollowers(account, lastFollower); | ||
}else{ | ||
console.log("Finished"); | ||
} | ||
}); | ||
} | ||
|
||
function timeToBreak(time,n){ | ||
if(time < last4week) return true; | ||
return false; | ||
} | ||
|
||
function link(account){ | ||
var url = "https://joticajulian.github.io/steem-activity/index.html"; | ||
return "<a href=" + url + "?lang="+language +"&account="+account + ">" + account + "</a>"; | ||
} | ||
|
||
function getQuery(){ | ||
var kvp = document.location.search.substr(1).split('&'); | ||
var account = ''; | ||
var text = ''; | ||
if(kvp != ''){ | ||
var i = kvp.length; | ||
var x; | ||
while (i--) { | ||
x = kvp[i].split('='); | ||
if (x[0] == 'account'){ | ||
account = x[1]; | ||
}else if (x[0] == 'lang'){ | ||
language = x[1]; | ||
load_language(); | ||
} | ||
} | ||
} | ||
return account; | ||
} | ||
|
||
function searchAccount(){ | ||
var url = "https://joticajulian.github.io/steem-activity/index.html?lang="+language+"&account=" + document.getElementById("input-account").value; | ||
console.log("opening: "+url); | ||
window.open(url, "_self"); | ||
} | ||
|
||
function extractUrlProfileImage(url){ | ||
if(url.substring(0,8) == "![image]"){ | ||
return url.substring(9, url.length - 1); | ||
} | ||
return url; | ||
} | ||
|
||
function load_language() { | ||
$(".is_ml").each(function() { | ||
$(this).html(label[language][$(this).attr("id")]) | ||
}) | ||
|
||
$(".is_ml_p").each(function() { | ||
$(this).attr('placeholder', label[language][$(this).attr("id")]) | ||
}) | ||
|
||
document.getElementById("timezone1").innerHTML = label[language]["Local time: "] + gmtToString(); | ||
document.getElementById("timezone2").innerHTML = label[language]["Local time: "] + gmtToString(); | ||
nameDay = label[language]["nameDay"]; | ||
}; | ||
|
||
function gmtToString(){ | ||
var text; | ||
var now = new Date(); | ||
var gmt = now.getTimezoneOffset(); | ||
|
||
if(gmt<=0) text = "GMT+"; | ||
else text = "GMT-"; | ||
|
||
var hour = Math.floor(Math.abs(gmt/60)); | ||
var minute = Math.abs(gmt)%60; | ||
text += pad(hour,2) + ":" + pad(minute,2); | ||
return text; | ||
} | ||
|
||
function pad(num, size) { | ||
var s = num+""; | ||
while (s.length < size) s = "0" + s; | ||
return s; | ||
} | ||
|
||
document.getElementById('input-account').onkeydown = function(e){ | ||
if(e.keyCode == 13){ | ||
e.preventDefault(); | ||
searchAccount(); | ||
} | ||
}; |