Commit b5d311f0 authored by s7_spruge_k's avatar s7_spruge_k
Browse files

basic month graphs

parent aa082b64
package com.example.calendar.controller;
import java.time.LocalDate;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -173,9 +174,84 @@ public class GraphController {
public String chooseCalPost(Model models, StatHelper statHelper, String calName)
{
statHelper.setChosenCalendar(calName);
System.out.println(statHelper);
models.addAttribute("statHelper", statHelper);
User currUser = findCurrentUser();
try
{
calendarRepo.findAllByUser(currUser);
}
catch(Exception e)
{
return "redirect:/add-new-calendar";
}
Calendar chosenCalendar = calendarRepo.findByName(calName);
try
{
ArrayList<Event> allEventsInCal = eventRepo.findAllByCalendar(chosenCalendar);
}
catch(Exception e)
{
System.out.println("Nav event kalendara");
return "redirect:/choose-cal";
}
ArrayList<Event> allEventsInCal = eventRepo.findAllByCalendar(chosenCalendar);
if(statHelper.getStatMethod().equals("Analysis by month"))
{
ArrayList<Integer> eventCountInMonths = new ArrayList<>();
LocalDate now = LocalDate.now();
for (int i = 1; i <= 12; i++) {
int temp = 0;
for (Event e : allEventsInCal) {
if(e.getStartDate().getMonthValue() == i && now.getYear() == e.getStartDate().getYear())
{
temp++;
}
}
eventCountInMonths.add(temp);
}
ArrayList<String> monthNames = new ArrayList<>();
monthNames.add("January");
monthNames.add("February");
monthNames.add("March");
monthNames.add("April");
monthNames.add("May");
monthNames.add("June");
monthNames.add("July");
monthNames.add("August");
monthNames.add("September");
monthNames.add("October");
monthNames.add("November");
monthNames.add("December");
JsonArray eventArray = new JsonArray();
for (int i = 0; i < eventCountInMonths.size(); i++) {
JsonObject eventJson = new JsonObject();
eventJson.addProperty("name", monthNames.get(i));
eventJson.addProperty("eventCount", eventCountInMonths.get(i));
eventArray.add(eventJson);
}
String title = "Event count each month in calendar: " + statHelper.getChosenCalendar();
models.addAttribute("name", title);
models.addAttribute("allEvents", eventArray);
}
else if(statHelper.getStatMethod().equals("Analysis by day"))
{
}
models.addAttribute("graphType", statHelper.getGraphMethod());
//models.addAttribute("statHelper", statHelper);
return "statsTest";
}
......
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<Head><title>StatHelper test</title></Head>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.1.0/fullcalendar.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Statistics</title>
</head>
<input type="hidden" id="events" th:value="${allEvents}"/>
<input type="hidden" id="name" th:value="${name}"/>
<input type="hidden" id="graphType" th:value="${graphType}"/>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script type="text/javascript">
var allEvents = JSON.parse(document.getElementById("events").value)
var name = document.getElementById("name").value
var graph = document.getElementById("graphType").value
window.onload = function () {
var dataFromEvents = [];
for (i = 0; i < allEvents.length; i++) {
dataFromEvents[i] = {
label: allEvents[i].name,
y: allEvents[i].eventCount
}
}
console.log(dataFromEvents);
var chart = new CanvasJS.Chart("chartContainer", {
title:{
text: name
},
axisX:{
interval: 1,
},
data: [
{
// Change type to "doughnut", "line", "splineArea", etc.
type: graph,
//dataPoints : dataFromEvents;
dataPoints: dataFromEvents
}
]
});
chart.render();
}
</script>
</head>
<body>
<h1 th:text="${statHelper.getChosenCalendar()}"></h1>
<h1 th:text="${statHelper.getGraphMethod()}"></h1>
<h1 th:text="${statHelper.getStatMethod()}"></h1>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<Head><title>Staats</title></Head>
<body>
<h1 th:text="${statHelper.getChosenCalendar()}"></h1>
<h1 th:text="${statHelper.getStatMethod()}"></h1>
<h1 th:text="${statHelper.getGraphMethod()}"></h1>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment