-
Notifications
You must be signed in to change notification settings - Fork 2
/
converter.go
64 lines (49 loc) · 1.85 KB
/
converter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"math"
"strconv"
)
func convertFahrenheitToCelsius(tempFahrenheit float64) float64 {
var tempCelsius = (tempFahrenheit - 32.0) * 5.0 / 9.0
return tempCelsius
}
func convertMercuryToHektopascal(pressureMercury float64) float64 {
return pressureMercury / 0.029529980164712
}
func convertInchToMm(lengthInch float64) float64 {
return lengthInch / 0.03937007874
}
func convertMphToKmh(speedMph float64) float64 {
return speedMph * 1.609344
}
func parseInteger(record string) int {
integer, _ := strconv.ParseInt(record, 10, 32)
return int(integer)
}
func parseFloat(record string) float32 {
float, _ := strconv.ParseFloat(record, 32)
return float32(float)
}
func parseTemperature(record string) (float32, float32) {
temperature, _ := strconv.ParseFloat(record, 32)
temperatureMetric := convertFahrenheitToCelsius(temperature)
return float32(math.Round(temperature*100) / 100), float32(math.Round(temperatureMetric*100) / 100)
}
func parsePressure(record string) (float32, float32) {
pressure, _ := strconv.ParseFloat(record, 32)
pressureMetric := convertMercuryToHektopascal(pressure)
return float32(math.Round(pressure*100) / 100), float32(math.Round(pressureMetric*100) / 100)
}
func parseRain(record string) (float32, float32) {
rain, _ := strconv.ParseFloat(record, 32)
rainMetric := convertInchToMm(rain)
return float32(math.Round(rain*100) / 100), float32(math.Round(rainMetric*100) / 100)
}
func parseSpeed(record string) (float32, float32) {
speed, _ := strconv.ParseFloat(record, 32)
speedMetric := convertMphToKmh(speed)
return float32(math.Round(speed*100) / 100), float32(math.Round(speedMetric*100) / 100)
}
func calculateAbsoluteHumidity(relativeHumidity int, temperature float64) float64 {
return (6.112 * math.Exp((17.67*temperature)/(temperature+243.5)) * float64(relativeHumidity) * 2.1674) / (273.15 + temperature)
}