mirror of https://github.com/MISP/misp-dashboard
Linked contribution_and_login to server
parent
b913f86e7b
commit
05c7c7a453
11
server.py
11
server.py
|
@ -470,5 +470,16 @@ def getTopOrglogin():
|
|||
data = users_helper.getTopOrglogin(date)
|
||||
return jsonify(data)
|
||||
|
||||
@app.route("/_getLoginVSCOntribution")
|
||||
def getLoginVSCOntribution():
|
||||
try:
|
||||
date = datetime.datetime.fromtimestamp(float(request.args.get('date')))
|
||||
except:
|
||||
date = datetime.datetime.now()
|
||||
|
||||
data = users_helper.getLoginVSCOntribution(date)
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='localhost', port=8001, threaded=True)
|
||||
|
|
|
@ -249,10 +249,11 @@ small {
|
|||
}
|
||||
function updateDatePieApi() {
|
||||
var date = datePickerWidgetApi.datepicker( "getDate" );
|
||||
$.getJSON( "{{ url_for('getUserLogins') }}"+"?date="+date.getTime()/1000, function( data ) {
|
||||
data = [{label: 'org1', data:[ Math.floor(Math.random() * 100) + 1]},
|
||||
{label: 'org2', data:[ Math.floor(Math.random() * 100) + 1]},
|
||||
{label: 'org3', data:[ Math.floor(Math.random() * 100) + 1]}]
|
||||
$.getJSON( "{{ url_for('getLoginVSCOntribution') }}"+"?date="+date.getTime()/1000, function( data ) {
|
||||
data = [
|
||||
{label: 'Has contributed during the day', data: data[0], color: '#4da74d' },
|
||||
{label: 'Has not contributed during the day', data:data[1], color: '#cb4b4b' }
|
||||
]
|
||||
|
||||
if (!pieApiWidget === undefined) {
|
||||
pieApiWidget.setData(toPlot);
|
||||
|
|
|
@ -26,12 +26,28 @@ class Users_helper:
|
|||
timestamps = [int(timestamp.decode('utf8')) for timestamp in timestamps]
|
||||
return timestamps
|
||||
|
||||
def getTopOrglogin(self, date, topNum=0):
|
||||
def getTopOrglogin(self, date, topNum=12):
|
||||
keyname = "LOGIN_ORG:{}".format(util.getDateStrFormat(date))
|
||||
data = self.serv_redis_db.zrange(keyname, 0, topNum-1, desc=True, withscores=True)
|
||||
data = [ [record[0].decode('utf8'), record[1]] for record in data ]
|
||||
return data
|
||||
|
||||
def getLoginVSCOntribution(self, date):
|
||||
keyname = "CONTRIB_DAY:{}".format(util.getDateStrFormat(date))
|
||||
orgs_contri = self.serv_redis_db.zrange(keyname, 0, -1, desc=True, withscores=False)
|
||||
orgs_contri = [ org.decode('utf8') for org in orgs_contri ]
|
||||
orgs_login = [ org[0] for org in self.getTopOrglogin(date, topNum=0) ]
|
||||
|
||||
contributed_num = 0
|
||||
non_contributed_num = 0
|
||||
for org in orgs_login:
|
||||
if org in orgs_contri:
|
||||
contributed_num += 1
|
||||
else:
|
||||
non_contributed_num +=1
|
||||
return [contributed_num, non_contributed_num]
|
||||
|
||||
|
||||
def getUserLoginsForPunchCard(self, date, prev_days=6):
|
||||
week = {}
|
||||
for curDate in util.getXPrevDaysSpan(date, prev_days):
|
||||
|
|
Loading…
Reference in New Issue