Skip to content
Snippets Groups Projects
Commit f183a8f0 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Corrected some calculations. Added a CVS util print class for REST services

parent c8968fe8
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (c) 2015 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSCommon.
* VIPSCommon is free software: you can redistribute it and/or modify
* it under the terms of the NIBIO Open Source License as published by
* NIBIO, either version 1 of the License, or (at your option) any
* later version.
*
* VIPSCommon is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with VIPSCommon. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.util;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.TimeZone;
import no.nibio.vips.entity.WeatherObservation;
/**
* @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class CSVPrintUtil {
public String printWeatherObservations(List<WeatherObservation> observations, TimeZone timeZone, String separator)
{
separator = separator == null ? "," : separator;
String retVal = "Time" + separator + "Parameter" + separator + "LogIntervalId" + separator + "Value\n";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssXXX");
format.setTimeZone(timeZone);
for(WeatherObservation observation:observations)
{
retVal += format.format(observation.getTimeMeasured()) + separator
+ observation.getElementMeasurementTypeId() + separator
+ observation.getLogIntervalId() + separator
+ observation.getValue() + "\n";
}
return retVal;
}
}
......@@ -271,8 +271,8 @@ public class SolarRadiationUtil {
if(hour > sunrise && hour < sunset)
{
double am = this.getAirMass(hour, dayOfYear, latitudeRad);
double x1 = Math.pow(0.7, am);
retVal = 1.353 * Math.pow(x1, 0.678);
//double x1 = Math.pow(0.7, am);
retVal = 1.353 * Math.pow(0.7, Math.pow(am, 0.678));
if(retVal > 1.1)
{
......@@ -356,7 +356,8 @@ public class SolarRadiationUtil {
Double hourAngle = Math.toRadians(15 * (hour - 12));
Double elevation = Math.asin(Math.sin(declinationRad) * Math.sin(latitudeRad) + Math.cos(declinationRad) * Math.cos(latitudeRad) * Math.cos(hourAngle));
Double zenithAngle = Math.toRadians(90.0) - elevation;
return 1 / (0.0001 + Math.cos(zenithAngle));
//return 1 / (0.0001 + Math.cos(zenithAngle));
return 1 / (Math.cos(zenithAngle) + 0.50572 * Math.pow(96.07995 - Math.toDegrees(zenithAngle),-1.6364));
}
}
......@@ -55,27 +55,54 @@ public class SolarRadiationUtilTest extends TestCase {
Calendar cal = Calendar.getInstance(timeZone);
cal.set(2015, Calendar.AUGUST, 8, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
/*double[] expected = {
0.0, // :00
0.0, // :01
0.0, // :02
0.0, // :03
0.0, // :04
0.28543339103038173, // :05
0.5268380531117902, // :06
0.6655907268348756, // :07
0.7516637378173253, // :08
0.806716626507543, // :09
0.8410912420487026, // :10
0.8600406096764159, // :11
0.8661031987320149, // :12
0.8600406096764159, // :13
0.8410912420487026, // :14
0.806716626507543, // :15
0.7516637378173253, // :16
0.6655907268348756, // :17
0.5268380531117902, // :18
0.28543339103038173, // :19
0.0, // :20
0.0, // :21
0.0, // :22
0.0 // :23
};*/
double[] expected = {
0.0, // :00
0.0, // :01
0.0, // :02
0.0, // :03
0.0, // :04
0.1618004720531765, // :05
0.4904056679049868, // :06
0.694612671066168, // :07
0.8163567559989782, // :08
0.8905554259500866, // :09
0.9351015843025755, // :10
0.9590133834488044, // :11
0.966562397281901, // :12
0.9590133834488044, // :13
0.9351015843025755, // :14
0.8905554259500866, // :15
0.8163567559989782, // :16
0.694612671066168, // :17
0.4904056679049868, // :18
0.1618004720531765, // :19
0.30585446462075766, // :05
0.5320290325650766, // :06
0.6674841256201908, // :07
0.75255528551197, // :08
0.8072260140456831, // :09
0.8414344839939248, // :10
0.8603110762175429, // :11
0.866352834115879, // :12
0.8603110762175429, // :13
0.8414344839939248, // :14
0.8072260140456831, // :15
0.75255528551197, // :16
0.6674841256201908, // :17
0.5320290325650766, // :18
0.30585446462075766, // :19
0.0, // :20
0.0, // :21
0.0, // :22
......@@ -162,7 +189,7 @@ public class SolarRadiationUtilTest extends TestCase {
cal.set(2015, Calendar.AUGUST, 8, 12, 0, 0);
Date date = cal.getTime();
SolarRadiationUtil instance = new SolarRadiationUtil();
Double expResult = 0.9540516211907254;
Double expResult = 0.8563620728824274;
Double result = instance.calculateSolarRadiationAtLocationAndTime(latitude, longitude, date, timeZone);
assertEquals(expResult, result);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment