Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
- Added Travis automatic build
Browse files Browse the repository at this point in the history
- Cleaning useless services
  • Loading branch information
maggima committed Oct 19, 2017
1 parent 059d796 commit aab806d
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 1,500 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: java
jdk:
- oraclejdk8

cache:
directories:
- $HOME/.m2

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,14 @@
*/
package ec.nbb.demetra.model.rest.utils;

import ec.nbb.demetra.json.excel.ExcelSeries;
import ec.tss.TsCollectionInformation;
import ec.tss.tsproviders.spreadsheet.engine.SpreadSheetFactory;
import ec.tss.tsproviders.spreadsheet.engine.TsExportOptions;
import ec.tss.tsproviders.spreadsheet.engine.TsImportOptions;
import ec.tss.tsproviders.utils.DataFormat;
import ec.tss.tsproviders.utils.ObsGathering;
import ec.tstoolkit.data.SubArray;
import ec.tstoolkit.data.Table;
import ec.tstoolkit.timeseries.simplets.TsDomain;
import ec.tstoolkit.timeseries.simplets.TsFrequency;
import ec.tstoolkit.timeseries.simplets.TsPeriod;
import ec.util.spreadsheet.helpers.ArraySheet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
*
Expand Down Expand Up @@ -67,80 +56,4 @@ public static int fromTsPeriod(TsPeriod p) {
int id = y * p.getFrequency().intValue() + pos;
return id;
}

public static TsCollectionInformation readExcelSeries(ExcelSeries series) {
List<List<Double>> data = series.getData();
List<String> periods;
SpreadSheetFactory gridFactory = SpreadSheetFactory.getDefault();
if (series.getPeriods() == null || series.getPeriods().isEmpty()) {
int size = 0;
if (data != null && !data.isEmpty() && data.get(0) != null) {
size = data.get(0).size();
}
TsDomain dom = new TsDomain(new TsPeriod(TsFrequency.valueOf(
series.getFreq()),
series.getFirstYear(),
series.getFirstPeriod()), size);
periods = dom
.stream()
.map(x -> ((TsPeriod) x).firstday().toString())
.collect(Collectors.toList());
} else {
periods = series.getPeriods();
}

ArraySheet.Builder asb = ArraySheet.builder();
if (series.getNames() != null && !series.getNames().isEmpty()) {
asb.row(0, 1, series.getNames());
} else {
asb.row(0, 1, IntStream.rangeClosed(1, series.getData().size())
.mapToObj(i -> "S" + i)
.collect(Collectors.toList()));
}

asb.column(1, 0, periods)
.name("Sheet");

for (int i = 0; i < series.getData().size(); i++) {
asb.column(1, i + 1, series.getData().get(i));
}
return gridFactory.toTsCollectionInfo(asb.build(), options);
}

public static ExcelSeries toExcelSeries(TsCollectionInformation coll) {
ExcelSeries s = new ExcelSeries();
SpreadSheetFactory gridFactory = SpreadSheetFactory.getDefault();
ArraySheet sheet = gridFactory.fromTsCollectionInfo(coll, export);
Table t = gridFactory.toTable(sheet);

// periods
SubArray<Date> p = t.column(0);
List<String> periods = new ArrayList<>();
for (int i = 1; i < p.getLength(); i++) {
periods.add(formatter.format(p.get(i)));
}
s.setPeriods(periods);

// data
List<List<Double>> data = new ArrayList<>();
for (int i = 1; i < t.getColumnsCount(); i++) {
SubArray<Double> col = t.column(i);
List<Double> d = new ArrayList<>();
for (int j = 1; j < t.getRowsCount(); j++) {
d.add(col.get(j));
}
data.add(d);
}
s.setData(data);

// names
SubArray<String> n = t.row(0);
List<String> names = new ArrayList<>();
for (int i = 1; i < n.getLength(); i++) {
names.add(n.get(i));
}
s.setNames(names);

return s;
}
}
Loading

0 comments on commit aab806d

Please sign in to comment.