1 package org.simantics.history.csv;
\r
3 import java.util.ArrayList;
\r
4 import java.util.List;
\r
7 * Specifies the interpolation method to use when producing exported samples in
\r
8 * {@link CSVFormatter}.
\r
10 * @author Tuukka Lehtonen
\r
13 public enum ExportInterpolation {
\r
16 * Directly take the last sample whose time stamp is less than or equal to
\r
17 * the sampling time.
\r
19 PREVIOUS_SAMPLE("Previous sample", "previous"),
\r
23 * v<sub>1</sub> v<sub>s</sub> v<sub>2</sub>
\r
24 * |----------------|--------------------|
\r
25 * t<sub>1</sub> t<sub>s</sub> t<sub>2</sub>
\r
28 * Here t<sub>1</sub> and t<sub>2</sub> are time stamps of those two
\r
29 * successive samples for which t<sub>1</sub> ≤ t<sub>s</sub> ≤
\r
33 * The sampling result is then:
\r
34 * <code>v<sub>s</sub> = v<sub>1</sub>+(v<sub>2</sub>-v<sub>1</sub>)*(t<sub>s</sub>-t<sub>1</sub>)/(t<sub>2</sub>-t<sub>1</sub>).
\r
36 LINEAR_INTERPOLATION("Linear interpolation", "lerp");
\r
38 public String label;
\r
39 public String preference;
\r
40 ExportInterpolation(String label, String preference) {
\r
42 this.preference = preference;
\r
44 public static List<ExportInterpolation> list() {
\r
45 return toList(LINEAR_INTERPOLATION, PREVIOUS_SAMPLE);
\r
47 public static ExportInterpolation fromIndex(int index) {
\r
48 return list().get(index);
\r
50 public static ExportInterpolation fromPreference(String preference) {
\r
51 for(ExportInterpolation s : list()) {
\r
52 if(s.preference.equals(preference)) return s;
\r
54 return list().get(0);
\r
56 public int index() {
\r
57 return list().indexOf(this);
\r
59 public static ExportInterpolation getDefault() {
\r
60 return LINEAR_INTERPOLATION;
\r
62 public String toPreference() {
\r
65 private static <T> List<T> toList(T ... ts) {
\r
66 ArrayList<T> result = new ArrayList<T>();
\r
67 for(T t : ts) result.add(t);
\r