Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java @ 7604:05549a84ee83
(issue1620) Add export of official lines in WST as specified
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 27 Nov 2013 16:21:00 +0100 |
parents | fe32a7f9655e |
children | 3e3a4f44423a |
comparison
equal
deleted
inserted
replaced
7603:25bce6e8beea | 7604:05549a84ee83 |
---|---|
23 | 23 |
24 import org.apache.log4j.Logger; | 24 import org.apache.log4j.Logger; |
25 | 25 |
26 import au.com.bytecode.opencsv.CSVWriter; | 26 import au.com.bytecode.opencsv.CSVWriter; |
27 | 27 |
28 import gnu.trove.TDoubleArrayList; | |
29 | |
30 import org.apache.commons.math.FunctionEvaluationException; | |
31 import org.apache.commons.math.analysis.UnivariateRealFunction; | |
32 | |
33 import org.apache.commons.math.analysis.interpolation.LinearInterpolator; | |
34 | |
28 import org.dive4elements.river.artifacts.model.ConstantWQKms; | 35 import org.dive4elements.river.artifacts.model.ConstantWQKms; |
29 | 36 |
30 import net.sf.jasperreports.engine.JasperExportManager; | 37 import net.sf.jasperreports.engine.JasperExportManager; |
31 import net.sf.jasperreports.engine.JasperFillManager; | 38 import net.sf.jasperreports.engine.JasperFillManager; |
32 import net.sf.jasperreports.engine.JasperPrint; | 39 import net.sf.jasperreports.engine.JasperPrint; |
46 import org.dive4elements.river.artifacts.StaticWQKmsArtifact; | 53 import org.dive4elements.river.artifacts.StaticWQKmsArtifact; |
47 import org.dive4elements.river.artifacts.model.CalculationResult; | 54 import org.dive4elements.river.artifacts.model.CalculationResult; |
48 import org.dive4elements.river.artifacts.model.Segment; | 55 import org.dive4elements.river.artifacts.model.Segment; |
49 import org.dive4elements.river.artifacts.model.WQCKms; | 56 import org.dive4elements.river.artifacts.model.WQCKms; |
50 import org.dive4elements.river.artifacts.model.WQKms; | 57 import org.dive4elements.river.artifacts.model.WQKms; |
58 import org.dive4elements.river.artifacts.model.WstLine; | |
51 import org.dive4elements.river.artifacts.model.WKmsJRDataSource; | 59 import org.dive4elements.river.artifacts.model.WKmsJRDataSource; |
52 import org.dive4elements.river.artifacts.model.WQKmsResult; | 60 import org.dive4elements.river.artifacts.model.WQKmsResult; |
53 import org.dive4elements.river.artifacts.resources.Resources; | 61 import org.dive4elements.river.artifacts.resources.Resources; |
54 | 62 |
55 import org.dive4elements.river.utils.RiverUtils; | 63 import org.dive4elements.river.utils.RiverUtils; |
759 protected void generateWST() | 767 protected void generateWST() |
760 throws IOException | 768 throws IOException |
761 { | 769 { |
762 logger.info("WaterlevelExporter.generateWST"); | 770 logger.info("WaterlevelExporter.generateWST"); |
763 | 771 |
764 int cols = data.get(0).length; | 772 int cols = data.get(0).length + officalFixings.size(); |
765 WstWriter writer = new WstWriter(cols); | 773 WstWriter writer = new WstWriter(cols); |
766 | 774 |
767 writeWSTData(writer); | 775 writeWSTData(writer); |
768 | 776 |
769 writer.write(out); | 777 writer.write(out); |
798 | 806 |
799 writer.addCorrected(result); | 807 writer.addCorrected(result); |
800 } | 808 } |
801 } | 809 } |
802 } | 810 } |
811 } | |
812 | |
813 // Append the official fixing interpolated to the calculation steps | |
814 // | |
815 // There was some confusion how to implement this. see flys/issue1620 | |
816 // for details. | |
817 for (WQKms wqkms: officalFixings) { | |
818 // To add some spaces here or to add them in the writer,.. | |
819 writer.addColumn(" " + getDesc(wqkms, true)); | |
820 | |
821 // Get all lines from the calculation | |
822 Map <Double, WstLine> calcLines = writer.getLines(); | |
823 | |
824 // All KM values where we have a point for | |
825 TDoubleArrayList officialKms = wqkms.allKms(); | |
826 | |
827 for (Map.Entry<Double, WstLine> entry : calcLines.entrySet()) { | |
828 // Bad for perfomance but the user can wait a bit for WST | |
829 // so lets not spend time optimizing too much,.. *hides* | |
830 double km = entry.getKey().doubleValue(); | |
831 int idx = officialKms.indexOf(km); | |
832 if (idx != -1) { | |
833 entry.getValue().add(wqkms.getW(idx), entry.getValue().getQ(0)); | |
834 } | |
835 } | |
836 | |
837 /* Variant: Interpolate the values | |
838 // Now get the lines for the of the calculation | |
839 Map <Double, WstLine> calcLines = writer.getLines(); | |
840 | |
841 // Create an interpolater for the official KM -> W relation | |
842 UnivariateRealFunction wFunc = new LinearInterpolator( | |
843 ).interpolate(wqkms.allKms().toNativeArray(), | |
844 wqkms.allWs().toNativeArray()); | |
845 | |
846 // Now for each calculated point add the interpolated official | |
847 for (Map.Entry<Double, WstLine> entry : calcLines.entrySet()) { | |
848 try { | |
849 double wVal = wFunc.value(entry.getKey().doubleValue()); | |
850 // Matching Q's are guranteed otherwise we would | |
851 // not have an official line | |
852 entry.getValue().add(wVal, entry.getValue().getQ(0)); | |
853 } | |
854 catch (FunctionEvaluationException aode) { | |
855 // should not happen | |
856 logger.error("spline interpolation failed", aode); | |
857 // entry.getValue().add(Double.NaN, entry.getValue().getQ(0)); | |
858 } | |
859 }*/ | |
860 | |
861 /* Variant: Add all official fixings | |
862 // Warning the WSTWriter does not handle this properly | |
863 // as it writes the points for which only a calculation | |
864 // exists in the first column | |
865 int size = wqkms.size(); | |
866 result = new double[4]; | |
867 for (int i = 0; i < size; i++) { | |
868 result = wqkms.get(i, result); | |
869 writer.add(result); | |
870 } | |
871 */ | |
803 } | 872 } |
804 } | 873 } |
805 | 874 |
806 | 875 |
807 /** | 876 /** |