using Bootstrap.DataAccess;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Controllers.Api
{
///
///
///
[Route("api/[controller]")]
[ApiController]
public class AnalyseController : ControllerBase
{
///
///
///
///
[HttpGet()]
public ActionResult Get([FromQuery]string logType = "")
{
var ret = new AnalyseData();
if (logType.Equals("LoginUsers", StringComparison.OrdinalIgnoreCase))
{
var loginUsers = LoginHelper.RetrieveAll(null, null, null);
var temp = loginUsers.GroupBy(usr => usr.LoginTime.ToString("yyyy-MM-dd"));
var max = temp.Any() ? temp.Max(g => g.Count()) : 1;
ret.Polylines = temp.Select((g, index) =>
{
ret.Datas.Add(new KeyValuePair(g.Key, g.Count().ToString()));
return $"{index * 2},{Math.Round(g.Count() * 28.0 / max, 2)}";
});
}
if (logType.Equals("trace", StringComparison.OrdinalIgnoreCase))
{
var loginUsers = TraceHelper.RetrieveAll(null, null, null);
var temp = loginUsers.GroupBy(usr => usr.LogTime.ToString("yyyy-MM-dd"));
var max = temp.Any() ? temp.Max(g => g.Count()) : 1;
ret.Polylines = temp.Select((g, index) =>
{
ret.Datas.Add(new KeyValuePair(g.Key, g.Count().ToString()));
return $"{index * 5},{Math.Round(g.Count() * 28.0 / max, 2)}";
});
}
if (logType.Equals("log", StringComparison.OrdinalIgnoreCase))
{
var loginUsers = LogHelper.RetrieveAll(null, null, null);
var temp = loginUsers.GroupBy(usr => usr.LogTime.ToString("yyyy-MM-dd"));
var max = temp.Any() ? temp.Max(g => g.Count()) : 1;
ret.Polylines = temp.Select((g, index) =>
{
ret.Datas.Add(new KeyValuePair(g.Key, g.Count().ToString()));
return $"{index * 5},{Math.Round(g.Count() * 28.0 / max, 2)}";
});
}
return ret;
}
///
///
///
public class AnalyseData
{
///
///
///
public IEnumerable Polylines { get; set; }
///
///
///
public List> Datas { get; set; } = new List>();
}
}
}