Skip to content

Instantly share code, notes, and snippets.

@ndroo
Created October 4, 2017 02:49
Show Gist options
  • Save ndroo/384bceeb16d771757b6996bd28001d8c to your computer and use it in GitHub Desktop.
Save ndroo/384bceeb16d771757b6996bd28001d8c to your computer and use it in GitHub Desktop.
package com.airthings.airthings;
import android.util.Log;
import java.util.Locale;
public class RadonColorCalculator {
private static final String TAG = RadonColorCalculator.class.getSimpleName();
private String countryCode;
private int radonCalcWindowHours;
private float redLongTermLevel;
private float redShortTermLevel;
private float yellowLevel;
public RadonColorCalculator() {
this.countryCode = "";
this.radonCalcWindowHours = 720;
this.yellowLevel = 100.0f;
this.redShortTermLevel = 1000.0f;
this.redLongTermLevel = 100.0f;
this.countryCode = Locale.getDefault().getCountry();
init();
}
RadonColorCalculator(Locale locale) {
this.countryCode = "";
this.radonCalcWindowHours = 720;
this.yellowLevel = 100.0f;
this.redShortTermLevel = 1000.0f;
this.redLongTermLevel = 100.0f;
this.countryCode = locale.getCountry();
init();
}
public RadonColorCalculator(float latitude, float longitude) {
this.countryCode = "";
this.radonCalcWindowHours = 720;
this.yellowLevel = 100.0f;
this.redShortTermLevel = 1000.0f;
this.redLongTermLevel = 100.0f;
init();
}
public RadonColorCalculator(String countryCode) {
this.countryCode = "";
this.radonCalcWindowHours = 720;
this.yellowLevel = 100.0f;
this.redShortTermLevel = 1000.0f;
this.redLongTermLevel = 100.0f;
if (countryCode == null) {
this.countryCode = Locale.getDefault().getCountry();
} else {
this.countryCode = countryCode;
}
init();
}
public RadonColorCalculator(float yellowLevel, float redLevel, int radonCalcWindowDays) {
this.countryCode = "";
this.radonCalcWindowHours = 720;
this.yellowLevel = 100.0f;
this.redShortTermLevel = 1000.0f;
this.redLongTermLevel = 100.0f;
this.radonCalcWindowHours = radonCalcWindowDays * 24;
this.yellowLevel = yellowLevel;
this.redShortTermLevel = redLevel;
this.redLongTermLevel = yellowLevel;
}
private void init() {
String str = this.countryCode;
Object obj = -1;
switch (str.hashCode()) {
case 2142:
if (str.equals("CA")) {
obj = 2;
break;
}
break;
case 2183:
if (str.equals("DK")) {
obj = 3;
break;
}
break;
case 2497:
if (str.equals("NO")) {
obj = null;
break;
}
break;
case 2642:
if (str.equals("SE")) {
obj = 4;
break;
}
break;
case 2718:
if (str.equals("US")) {
obj = 1;
break;
}
break;
}
switch (obj) {
case null:
this.radonCalcWindowHours = 1440;
this.yellowLevel = 100.0f;
this.redShortTermLevel = 1000.0f;
this.redLongTermLevel = 100.0f;
return;
case 1:
this.radonCalcWindowHours = 720;
this.yellowLevel = 148.0f;
this.redShortTermLevel = MeasurementDefines.US_RADON_SHORT_TERM_RED_LEVEL;
this.redLongTermLevel = 148.0f;
return;
case 2:
this.radonCalcWindowHours = MeasurementDefines.CA_SHORT_TERM_DURATION_HOURS;
this.yellowLevel = 300.0f;
this.redShortTermLevel = 1000.0f;
this.redLongTermLevel = 300.0f;
return;
case 3:
this.radonCalcWindowHours = 1440;
this.yellowLevel = 200.0f;
this.redShortTermLevel = 1000.0f;
this.redLongTermLevel = 200.0f;
return;
case 4:
this.radonCalcWindowHours = 1440;
this.yellowLevel = 200.0f;
this.redShortTermLevel = 1000.0f;
this.redLongTermLevel = 200.0f;
return;
default:
this.radonCalcWindowHours = 720;
this.yellowLevel = 100.0f;
this.redShortTermLevel = 1000.0f;
this.redLongTermLevel = 100.0f;
return;
}
}
public float getYellowLevel() {
return this.yellowLevel;
}
public float getShortTermRedLevel() {
return this.redShortTermLevel;
}
public int getRadonCalcWindowHours() {
return this.radonCalcWindowHours;
}
public int determineColorForAverageOverTime(float radonLevel, int numHours) {
if (numHours < 1) {
return 0;
}
return determineColor(numHours, radonLevel);
}
private int determineColor(int numHours, float radonLevel) {
Log.d(TAG, "num hours: " + numHours + ", radonLevel:" + radonLevel);
if (radonLevel < this.yellowLevel) {
return 1;
}
if (numHours < this.radonCalcWindowHours) {
if (radonLevel < this.redShortTermLevel) {
return 2;
}
return 3;
} else if (radonLevel < this.redLongTermLevel) {
return 1;
} else {
return 3;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment