diff --git a/Calculations/haskell/solarduino-haskell/.idea/.gitignore b/Calculations/haskell/solarduino-haskell/.idea/.gitignore deleted file mode 100644 index 5c98b42..0000000 --- a/Calculations/haskell/solarduino-haskell/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/Calculations/haskell/solarduino-haskell/.idea/runConfigurations/Main.xml b/Calculations/haskell/solarduino-haskell/.idea/runConfigurations/Main.xml deleted file mode 100644 index a59ee52..0000000 --- a/Calculations/haskell/solarduino-haskell/.idea/runConfigurations/Main.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - \ No newline at end of file diff --git a/Calculations/haskell/solarduino-haskell/.idea/runConfigurations/REPL.xml b/Calculations/haskell/solarduino-haskell/.idea/runConfigurations/REPL.xml deleted file mode 100644 index 885b5c4..0000000 --- a/Calculations/haskell/solarduino-haskell/.idea/runConfigurations/REPL.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - \ No newline at end of file diff --git a/Calculations/haskell/solarduino-haskell/app/Main.hs b/Calculations/haskell/solarduino-haskell/app/Main.hs index bb4877e..317ecb1 100644 --- a/Calculations/haskell/solarduino-haskell/app/Main.hs +++ b/Calculations/haskell/solarduino-haskell/app/Main.hs @@ -11,7 +11,7 @@ import TimeConverters --main :: IO () --main = print (directPower 10 0.5) -main = writeBestAnglesToFile "angles.times" (fromGregorian 2019 8 13) (fromGregorian 2019 8 20) 10000 100 +main = writeBestAnglesToFile "angles.times" (fromGregorian 2019 8 15) (fromGregorian 2019 8 15) 10000 100 ---- | Benchmark functions using Criterion. --main = defaultMain [ -- bgroup "benchmarking..." [ -- would usually be function name here diff --git a/SolAppduino/SolArduino/app/build.gradle b/SolAppduino/SolArduino/app/build.gradle index 92ebc83..a767f03 100644 --- a/SolAppduino/SolArduino/app/build.gradle +++ b/SolAppduino/SolArduino/app/build.gradle @@ -67,6 +67,9 @@ dependencies { // Bottom App Bar implementation 'com.android.support:design:28.0.0' + + // Charts + implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' } android { diff --git a/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/MainActivity.kt b/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/MainActivity.kt index 648d96a..c7b241b 100644 --- a/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/MainActivity.kt +++ b/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/MainActivity.kt @@ -3,7 +3,7 @@ package com.abbyberkers.solarduino import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.abbyberkers.solarduino.ui.HomeFragment -import com.abbyberkers.solarduino.ui.ScheduleFragment +import com.abbyberkers.solarduino.ui.schedule.ScheduleFragment import com.abbyberkers.solarduino.ui.replace import kotlinx.android.synthetic.main.activity_main.* diff --git a/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/ScheduleFragment.kt b/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/ScheduleFragment.kt deleted file mode 100644 index 0fa3b79..0000000 --- a/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/ScheduleFragment.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.abbyberkers.solarduino.ui - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import com.abbyberkers.solarduino.R - -class ScheduleFragment : Fragment() { - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = - inflater.inflate(R.layout.schedule_fragment, container, false) - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - } -} \ No newline at end of file diff --git a/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/AxisTimeFormatter.kt b/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/AxisTimeFormatter.kt new file mode 100644 index 0000000..6ff4895 --- /dev/null +++ b/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/AxisTimeFormatter.kt @@ -0,0 +1,19 @@ +package com.abbyberkers.solarduino.ui.schedule + +import com.github.mikephil.charting.components.AxisBase +import com.github.mikephil.charting.formatter.ValueFormatter +import java.text.SimpleDateFormat +import java.util.* + +/** + * Formatter for axis values. + */ +class AxisTimeFormatter : ValueFormatter() { + /** + * Formats a value given in seconds since 01-01-1970 as HH:mm. + */ + override fun getAxisLabel(value: Float, axis: AxisBase?): String { + val format = SimpleDateFormat("HH:mm", Locale.getDefault()) + return format.format(value * 1000) + } +} \ No newline at end of file diff --git a/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/ScheduleChart.kt b/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/ScheduleChart.kt new file mode 100644 index 0000000..cd007df --- /dev/null +++ b/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/ScheduleChart.kt @@ -0,0 +1,36 @@ +package com.abbyberkers.solarduino.ui.schedule + +import android.content.Context +import com.abbyberkers.solarduino.R +import com.github.mikephil.charting.charts.LineChart +import com.github.mikephil.charting.data.Entry +import com.github.mikephil.charting.data.LineData +import com.github.mikephil.charting.data.LineDataSet + +/** + * A chart with the schedule for today's angles. + */ +class ScheduleChart(private val data: List, + private val chart: LineChart, + private val context: Context) { + + init { + val entries = this.data.map { Entry(it.time, it.angle) } + val dataSet = LineDataSet(entries, "label") + // Style the chart with the apps colors. + dataSet.apply { + color = context.getColor(R.color.colorAccent) + setCircleColor(context.getColor(R.color.colorAccent)) + } + val lineData = LineData(dataSet) + + this.chart.apply { + data = lineData + description.isEnabled = false + legend.isEnabled = false + xAxis.valueFormatter = AxisTimeFormatter() + invalidate() // Refresh the chart. + } + } +} + diff --git a/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/ScheduleFragment.kt b/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/ScheduleFragment.kt new file mode 100644 index 0000000..88c757c --- /dev/null +++ b/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/ScheduleFragment.kt @@ -0,0 +1,35 @@ +package com.abbyberkers.solarduino.ui.schedule + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import com.abbyberkers.solarduino.R + +class ScheduleFragment : Fragment() { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = + inflater.inflate(R.layout.schedule_fragment, container, false) + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + ScheduleChart(getChartData(), view.findViewById(R.id.schedule_chart), context!!) + } + + /** + * TODO get the data from the Pi instead of our own little file located in /res/raw. + * TODO move to PanelRequestSender? + * + * Gets the data for the schedule chart. + */ + private fun getChartData(): List { + val rawId = resources.getIdentifier("angles", "raw", "com.abbyberkers.solarduino") + return resources.openRawResource(rawId).bufferedReader().useLines { lines -> + lines.map { + val angleTime = it.split(" ") + SchedulePoint(angle = angleTime.first().toFloat(), + time = angleTime.last().toFloat()) + }.toList() + } + } +} \ No newline at end of file diff --git a/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/SchedulePoint.kt b/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/SchedulePoint.kt new file mode 100644 index 0000000..b2cdf9e --- /dev/null +++ b/SolAppduino/SolArduino/app/src/main/kotlin/com/abbyberkers/solarduino/ui/schedule/SchedulePoint.kt @@ -0,0 +1,3 @@ +package com.abbyberkers.solarduino.ui.schedule + +data class SchedulePoint(val angle: Float, val time: Float) \ No newline at end of file diff --git a/SolAppduino/SolArduino/app/src/main/res/layout/schedule_fragment.xml b/SolAppduino/SolArduino/app/src/main/res/layout/schedule_fragment.xml index a181207..18e1645 100644 --- a/SolAppduino/SolArduino/app/src/main/res/layout/schedule_fragment.xml +++ b/SolAppduino/SolArduino/app/src/main/res/layout/schedule_fragment.xml @@ -1,12 +1,12 @@ + android:layout_height="match_parent" + android:padding="@dimen/activity_horizontal_margin"> - + \ No newline at end of file diff --git a/SolAppduino/SolArduino/app/src/main/res/menu/menu.xml b/SolAppduino/SolArduino/app/src/main/res/menu/menu.xml index 7343190..19cfc99 100644 --- a/SolAppduino/SolArduino/app/src/main/res/menu/menu.xml +++ b/SolAppduino/SolArduino/app/src/main/res/menu/menu.xml @@ -6,7 +6,7 @@ android:id="@+id/home_button" android:enabled="true" android:icon="@drawable/ic_home" - android:title="Home" + android:title="@string/home" app:showAsAction="always" /> \ No newline at end of file diff --git a/SolAppduino/SolArduino/app/src/main/res/raw/angles.times b/SolAppduino/SolArduino/app/src/main/res/raw/angles.times new file mode 100644 index 0000000..070479f --- /dev/null +++ b/SolAppduino/SolArduino/app/src/main/res/raw/angles.times @@ -0,0 +1,100 @@ +0.0 1565843217.6 +33.1076996727392 1565843744.7 +42.94448583661988 1565844271.9 +46.05020230051852 1565844799.1 +47.60489906817322 1565845326.2 +48.46266986812638 1565845853.4 +48.94012277717066 1565846380.6 +49.190748484736126 1565846907.8 +49.30713689873636 1565847434.9 +49.33233992112289 1565847962.1 +49.29751020080393 1565848489.3 +49.210001880600984 1565849016.4 +49.09361346660076 1565849543.6 +48.94607240369233 1565850070.8 +48.782955016329794 1565850597.9 +48.60058423310239 1565851125.1 +48.39668749889922 1565851652.3 +48.189113693285286 1565852179.5 +47.965963563217265 1565852706.6 +47.72723710869512 1565853233.8 +47.48256102765132 1565853761 +47.23420787519676 1565854288.1 +46.970278398288094 1565854815.3 +46.70039929485775 1565855342.5 +46.42089349349499 1565855869.6 +46.13543806561055 1565856396.8 +45.84035593979368 1565856924 +45.53564711604438 1565857451.2 +45.221311594362646 1565857978.3 +44.90102644615926 1565858505.5 +44.57111460002343 1565859032.7 +44.23525312736592 1565859559.8 +43.88381533025432 1565860087 +43.52502339032119 1565860614.2 +43.158009268755485 1565861141.4 +42.77174175132491 1565861668.5 +42.381797162483586 1565862195.7 +41.97400369407725 1565862722.9 +41.556583527738475 1565863250 +41.125859592056514 1565863777.2 +40.677286776809545 1565864304.4 +40.21541019221937 1565864831.5 +39.73428021176435 1565865358.7 +39.23530135174431 1565865885.9 +38.717069095859415 1565866413.1 +38.18326051552041 1565866940.2 +37.624248912794876 1565867467.4 +37.0400342876828 1565867994.6 +36.430616640184205 1565868521.7 +35.79599597029908 1565869048.9 +35.13389972291649 1565869576.1 +34.43924631032587 1565870103.2 +33.70749062230538 1565870630.4 +32.938632658855 1565871157.6 +32.137217530196565 1565871684.8 +31.283123801654163 1565872211.9 +30.388250726271128 1565872739.1 +29.437021979593357 1565873266.3 +28.437659743253423 1565873793.4 +27.370042582575426 1565874320.6 +26.23644305267025 1565874847.8 +25.03318408212715 1565875375 +23.746093862791877 1565875902.1 +22.373767878364575 1565876429.3 +20.90657943091281 1565876956.5 +19.330356712282338 1565877483.6 +17.643695206173298 1565878010.8 +15.825068961609935 1565878538 +13.868528352070564 1565879065.1 +11.75849705310109 1565879592.3 +9.481671295358318 1565880119.5 +7.0224747543881465 1565880646.7 +4.371280732258147 1565881173.8 +1.5102403494033085 1565881701 +0.0 1565882228.2 +0.0 1565882755.3 +0.0 1565883282.5 +0.0 1565883809.7 +0.0 1565884336.8 +0.0 1565884864 +0.0 1565885391.2 +0.0 1565885918.4 +0.0 1565886445.5 +0.0 1565886972.7 +0.0 1565887499.9 +0.0 1565888027 +0.0 1565888554.2 +0.0 1565889081.4 +0.0 1565889608.6 +0.0 1565890135.7 +0.0 1565890662.9 +0.0 1565891190.1 +0.0 1565891717.2 +0.0 1565892244.4 +0.0 1565892771.6 +0.0 1565893298.7 +0.0 1565893825.9 +0.0 1565894353.1 +0.0 1565894880.3 +0.0 1565895407.4 diff --git a/SolAppduino/SolArduino/app/src/main/res/values-nl/strings.xml b/SolAppduino/SolArduino/app/src/main/res/values-nl/strings.xml index 93cb8cc..521d98d 100644 --- a/SolAppduino/SolArduino/app/src/main/res/values-nl/strings.xml +++ b/SolAppduino/SolArduino/app/src/main/res/values-nl/strings.xml @@ -9,4 +9,6 @@ Knop omlaag Knop omhoog Draai panelen + Thuis + Planning \ No newline at end of file diff --git a/SolAppduino/SolArduino/app/src/main/res/values/strings.xml b/SolAppduino/SolArduino/app/src/main/res/values/strings.xml index 6488453..9541121 100644 --- a/SolAppduino/SolArduino/app/src/main/res/values/strings.xml +++ b/SolAppduino/SolArduino/app/src/main/res/values/strings.xml @@ -8,5 +8,7 @@ 42° Solar Panel Set angle - Check for updates + Check for updates + Home + Schedule diff --git a/SolAppduino/SolArduino/build.gradle b/SolAppduino/SolArduino/build.gradle index aedd371..49415d2 100644 --- a/SolAppduino/SolArduino/build.gradle +++ b/SolAppduino/SolArduino/build.gradle @@ -5,7 +5,7 @@ buildscript { repositories { google() jcenter() - + maven { url 'https://jitpack.io' } } dependencies { classpath 'com.android.tools.build:gradle:3.4.2' @@ -28,7 +28,7 @@ allprojects { repositories { google() jcenter() - + maven { url 'https://jitpack.io' } } }