Skip to content

Instantly share code, notes, and snippets.

@Roboneet
Last active April 27, 2018 16:01
Show Gist options
  • Save Roboneet/f0f17ceee89d9909b7c11325f83b1c9d to your computer and use it in GitHub Desktop.
Save Roboneet/f0f17ceee89d9909b7c11325f83b1c9d to your computer and use it in GitHub Desktop.
An easy way to fill preferences in http://psd.bits-pilani.ac.in/
/***
When you are too lazy to drag stuff (and 295 of them)
( An easy way to fill preferences in http://psd.bits-pilani.ac.in/ )
res : contents of getPBDetail which is loaded in http://psd.bits-pilani.ac.in/Student/ViewProblemBanks.aspx
***/
// #just_snippets
// get info of all stations
info = eval(res.d)
// create an array containing distinct values of any key
var indPref = info.map(e => e.IndustryDomain).reduce(function(acc, e){
if(acc.indexOf(e) == -1){
acc.push(e)
}
return acc
}, [])
// helpers to manipuate the prefrence array
function swap(arr, a, b){
var t = arr[a];
arr[a] = arr[b];
arr[b] = t;
return arr;
}
function move(arr, a, b){
l = arr[a];
arr.splice(a, 1);
arr.splice(b, 0, l);
return arr;
}
// preference settings
var pref = [{
arr: indPref,
key: "IndustryDomain",
weight: 15
},
{
arr: cityPref,
key: "City",
weight: 20
}
]
// score of a station
function score(a){
var score = pref.reduce((acc, e)=>{
var len = e.arr.length;
return acc + e.weight*(len - e.arr.indexOf(a[e.key])/len);
}, 0)
score *= ((a.Tags.search("A7") == -1)?1:2);
score += a.totalstudent/10;
return score
}
// sort and print info
function sp(){
info.sort((a, b)=>{
return score(b) - score(a)
})
info.forEach((e)=>{
console.log(e.City + " "+ e.IndustryDomain + " "+ e.CompanyName);
});
}
// make a string to be sent to be saved
var str = "[";
info.forEach((el, i)=>{
str += "{"
str += "'isActive':'1',"
str += "'PreferenceNo':'" + (i + 1) + "','StationId':'" + el.StationId + "',"
str += "'Accommodation':'" + "true" + "'," // this comma!
str += "},"
})
str = str.substr(0, str.length - 1);
str += "]";
// save the preference
saveprefdata(str, "", 0) // run this from http://psd.bits-pilani.ac.in/Student/StudentStationPreference.aspx
// tadaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment