-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from sboschman/master
loess interpolatie voor de grafieken
- Loading branch information
Showing
14 changed files
with
308 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/nl/topicus/onderwijs/dashboard/datasources/LastServerCheckTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
package nl.topicus.onderwijs.dashboard.datasources; | |||
|
|||
import java.util.Date; | |||
|
|||
import nl.topicus.onderwijs.dashboard.modules.DataSource; | |||
import nl.topicus.onderwijs.dashboard.modules.DataSourceSettings; | |||
|
|||
@DataSourceSettings(label = "Last servercheck", htmlClass = "date", type = Date.class) | |||
public interface LastServerCheckTime extends DataSource<Date> { | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/nl/topicus/onderwijs/dashboard/modules/plots/DataSourceSeries.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,78 @@ | |||
package nl.topicus.onderwijs.dashboard.modules.plots; | |||
|
|||
import java.io.Serializable; | |||
import java.util.Collections; | |||
import java.util.Date; | |||
import java.util.Iterator; | |||
import java.util.LinkedList; | |||
import java.util.List; | |||
|
|||
import nl.topicus.onderwijs.dashboard.datasources.LastServerCheckTime; | |||
import nl.topicus.onderwijs.dashboard.keys.Key; | |||
import nl.topicus.onderwijs.dashboard.modules.DashboardRepository; | |||
import nl.topicus.onderwijs.dashboard.modules.DataSource; | |||
|
|||
public class DataSourceSeries<T extends Number, D extends DataSource<T>> | |||
implements Serializable { | |||
private static final long serialVersionUID = 1L; | |||
private Key key; | |||
private Class<D> dataSource; | |||
private LinkedList<DataSourceSeriesEntry<T>> data = new LinkedList<DataSourceSeriesEntry<T>>(); | |||
|
|||
public DataSourceSeries(Key key, Class<D> dataSource) { | |||
this.key = key; | |||
this.dataSource = dataSource; | |||
} | |||
|
|||
public Key getKey() { | |||
return key; | |||
} | |||
|
|||
public Class<D> getDataSource() { | |||
return dataSource; | |||
} | |||
|
|||
public List<DataSourceSeriesEntry<T>> getData() { | |||
return Collections.unmodifiableList(data); | |||
} | |||
|
|||
public DataSourceSeriesEntry<T> getFirstEntry() { | |||
return data.getFirst(); | |||
} | |||
|
|||
public DataSourceSeriesEntry<T> getLastEntry() { | |||
return data.isEmpty() ? null : data.getLast(); | |||
} | |||
|
|||
public void addEntry(DashboardRepository repository) { | |||
LastServerCheckTime time = repository | |||
.getData(LastServerCheckTime.class).get(key); | |||
Date timeValue = time == null ? null : time.getValue(); | |||
if (timeValue == null) | |||
return; | |||
|
|||
D source = repository.getData(dataSource).get(key); | |||
T value = source == null ? null : source.getValue(); | |||
|
|||
if ((data.isEmpty() || data.getLast().getKey().before(timeValue)) | |||
&& value != null) | |||
data.add(new DataSourceSeriesEntry<T>(timeValue, value)); | |||
} | |||
|
|||
/** | |||
* Removes any data with date older than ttlDate. | |||
* | |||
* @param ttlDate | |||
*/ | |||
public void cleanupEntries(Date ttlDate) { | |||
Iterator<DataSourceSeriesEntry<T>> iter = data.iterator(); | |||
while (iter.hasNext()) { | |||
DataSourceSeriesEntry<T> entry = iter.next(); | |||
if (entry.getKey().before(ttlDate)) | |||
iter.remove(); | |||
else | |||
return; // stop if date is after ttlDate, the series is ordered | |||
// chronologically. | |||
} | |||
} | |||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/nl/topicus/onderwijs/dashboard/modules/plots/DataSourceSeriesEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
package nl.topicus.onderwijs.dashboard.modules.plots; | |||
|
|||
import java.io.Serializable; | |||
import java.util.Date; | |||
|
|||
public class DataSourceSeriesEntry<T extends Number> implements Serializable { | |||
private static final long serialVersionUID = 1L; | |||
|
|||
private Date key; | |||
|
|||
private T value; | |||
|
|||
public DataSourceSeriesEntry(Date key, T value) { | |||
this.key = key; | |||
this.value = value; | |||
} | |||
|
|||
public Date getKey() { | |||
return key; | |||
} | |||
|
|||
public void setKey(Date key) { | |||
this.key = key; | |||
} | |||
|
|||
public T getValue() { | |||
return value; | |||
} | |||
|
|||
public void setValue(T value) { | |||
this.value = value; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.