Skip to content

Commit

Permalink
#24 Remove obsolete Google visualisation code
Browse files Browse the repository at this point in the history
  • Loading branch information
awconstable committed Mar 9, 2021
1 parent 90e7e20 commit 3ab9cb4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 100 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.visualization</groupId>
<artifactId>visualization-datasource</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.google.visualization</groupId>
<artifactId>visualization-datasource</artifactId>
</dependency>

<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
Expand Down
100 changes: 10 additions & 90 deletions web/src/main/java/com/austenconstable/web/trend/TrendController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.google.visualization.datasource.base.TypeMismatchException;
import com.google.visualization.datasource.datatable.ColumnDescription;
import com.google.visualization.datasource.datatable.DataTable;
import com.google.visualization.datasource.datatable.TableCell;
import com.google.visualization.datasource.datatable.TableRow;
import com.google.visualization.datasource.datatable.value.DateValue;
import com.google.visualization.datasource.datatable.value.ValueType;
import com.google.visualization.datasource.render.JsonRenderer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.mobile.device.Device;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.math.RoundingMode;
Expand All @@ -35,8 +30,6 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.time.temporal.TemporalField;
import java.time.temporal.WeekFields;
import java.util.*;

Expand Down Expand Up @@ -69,81 +62,8 @@ public static double round(double value, int places) {
return bd.doubleValue();
}

@Deprecated
@RequestMapping("/trend/monthly/{team}")
@ResponseBody
public String rollingMonthlyTrend(Model model, @PathVariable String team) {

DataTable data = new DataTable();

data.addColumn(new ColumnDescription("month", ValueType.DATE, "Month"));
data.addColumn(new ColumnDescription("happiness", ValueType.NUMBER, "Happiness"));
data.addColumn(new ColumnDescription("responses", ValueType.NUMBER, "Responses"));

try {
ArrayList<TableRow> rows = new ArrayList<>();

ArrayList<HappinessTrend> trends = trendService.getMonthlyTrendData(team);

for (HappinessTrend trend:trends) {
TableRow tr = new TableRow();
tr.addCell(new TableCell(new DateValue(trend.getTrendDate().getYear(), trend.getTrendDate().getMonth().getValue() - 1, 1)
, trend.getTrendDate().getMonth().getDisplayName(TextStyle.SHORT, Locale.ENGLISH)));
tr.addCell(trend.getAvgHappinessRating());
tr.addCell(trend.getResponseCount());
rows.add(tr);
}

data.addRows(rows);

} catch (TypeMismatchException e) {
System.out.print(e);
}

return JsonRenderer.renderDataTable(data, true, true, false).toString();

}

@Deprecated
@RequestMapping("/trend/weekly/{team}")
@ResponseBody
public String rollingWeeklyTrend(Model model, @PathVariable String team) {

DataTable data = new DataTable();

data.addColumn(new ColumnDescription("week", ValueType.DATE, "Week"));
data.addColumn(new ColumnDescription("happiness", ValueType.NUMBER, "Happiness"));
data.addColumn(new ColumnDescription("responses", ValueType.NUMBER, "Responses"));

try {
ArrayList<TableRow> rows = new ArrayList<>();

ArrayList<HappinessTrend> trends = trendService.getWeeklyTrendData(team);

TemporalField woy = WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear();

for (HappinessTrend trend:trends) {
TableRow tr = new TableRow();
tr.addCell(new TableCell(new DateValue(trend.getTrendDate().getYear(), trend.getTrendDate().getMonth().getValue() - 1, trend.getTrendDate().getDayOfMonth())
, "Week " + trend.getTrendDate().get(woy) + ", " + trend.getTrendDate().getMonth().getDisplayName(TextStyle.SHORT, Locale.ENGLISH)
+ " " + trend.getTrendDate().getYear()));
tr.addCell(trend.getAvgHappinessRating());
tr.addCell(trend.getResponseCount());
rows.add(tr);
}

data.addRows(rows);

} catch (TypeMismatchException e) {
System.out.print(e);
}

return JsonRenderer.renderDataTable(data, true, true, false).toString();

}

@GetMapping("/")
public String index(Device device) throws Exception {
public String index(Device device) {

if(device.isMobile() || device.isTablet()){
return "thankyou";
Expand All @@ -153,13 +73,13 @@ public String index(Device device) throws Exception {
}

@GetMapping("/chart")
public String chart() throws Exception {
public String chart() {
return "trendgraph";
}

@GetMapping("/thankyou")
public String thankyou(Device device, @RequestParam(name="team", required = true) String teamId,
@RequestParam(name="rating", required = false) String rating, Model model) throws Exception {
public String thankyou(Device device, @RequestParam(name="team") String teamId,
@RequestParam(name="rating", required = false) String rating, Model model) {

HierarchyEntity team = hierarchyClient.findEntityBySlug(teamId);

Expand Down Expand Up @@ -192,7 +112,7 @@ private LineDataset createTrendDataSet(String dataSetName, HashMap<String, Doub
dataset.setPointBackgroundColor(pointsColors);
if(child)
{
dataset.setBorderDash(new ArrayList<Integer>(Arrays.asList(new Integer[]{5, 5})));
dataset.setBorderDash(new ArrayList<Integer>(Arrays.asList(5, 5)));
}
dataset.setYAxisID("y-axis-1");
return dataset;
Expand All @@ -210,7 +130,7 @@ private LineDataset createCountDataSet(String dataSetName, HashMap<String, Inte
dataset.setPointBackgroundColor(pointsColors);
if(child)
{
dataset.setBorderDash(new ArrayList<Integer>(Arrays.asList(new Integer[]{5, 5})));
dataset.setBorderDash(new ArrayList<Integer>(Arrays.asList(5, 5)));
}
dataset.setYAxisID("y-axis-2");
return dataset;
Expand Down

0 comments on commit 3ab9cb4

Please sign in to comment.