Skip to content

Commit

Permalink
Added icons and hourly screen almost done.
Browse files Browse the repository at this point in the history
Changed PTI calculation formula
  • Loading branch information
orl0pl committed Feb 23, 2023
1 parent 7efe90c commit 79fbf37
Show file tree
Hide file tree
Showing 46 changed files with 666 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ npm-debug.*
*.mobileprovision
*.orig.*
web-build/

API_KEY.js
# macOS
.DS_Store
8 changes: 4 additions & 4 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import HourlyScreen from "./components/HourlyScreen";
import * as Location from "expo-location";
import axios from "axios";
import * as Localization from 'expo-localization';
import i18next from 'i18next';
import i18next, { t } from 'i18next';
import API_KEY from './API_KEY';
const pl = require('./components/utils/pl.json');
const en = require('./components/utils/en.json');
i18next.init({
Expand All @@ -41,7 +42,6 @@ export default function App() {
const [weather, setWeather] = useState({});
const [search, setSearch] = useState("");
const [language, setLanguage] = useState("en");
const API_KEY = "8bf38ea1cc24c809acd8484cf88ad776";
function useI18n() {
const language = useSelector(store => store.language);

Expand Down Expand Up @@ -87,7 +87,7 @@ export default function App() {
console.log(mode);
if (mode === "location") {
getAndSetLocation();

} else if (mode === "city") {
ToastAndroid.show("Searching city: "+search, ToastAndroid.SHORT);
fetch(
Expand Down Expand Up @@ -208,7 +208,7 @@ export default function App() {
/>
<Tab.Screen
name={i18next.t('navigation.hourly')}
children={() => <HourlyScreen weather={weather} theme={theme} />}
children={() => <HourlyScreen t={t} weather={weather} theme={theme} />}
options={{
tabBarLabel: i18next.t('navigation.hourly'),
tabBarIcon: ({ color, size }) => (
Expand Down
8 changes: 7 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
}
},
"package": "com.orl0pl.meteo"
},
"web": {
"favicon": "./assets/favicon.png"
},
"extra": {
"eas": {
"projectId": "38d04e0e-fb9a-4fc5-aa6b-b427cd600ced"
}
}
}
}
65 changes: 11 additions & 54 deletions components/CurrentScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,15 @@ import { View, ScrollView, StyleSheet } from "react-native";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import iconMap from "./iconMap";
import { Text, ActivityIndicator, Divider, MD3LightTheme } from "react-native-paper";
import { calculatePTI } from "./utils/PTI";
import { calculatePTI, calculatePTIOWM } from "./utils/PTI";
import TopCurrent from "./components/TopCurrent";
import { FlexiCard } from "./components/Cards";
import moment from "moment";
import "moment/min/locales";
import * as Localization from "expo-localization";
import { RainComponent, UmbrellaIconReactive } from "./components/Bars";
moment.locale(Localization.locale.slice(0,2));
/**
* @param {number} temp temperature in celsius
* @param {number} humidity humidity in percentage
* @param {number} windSpeed wind speed in m/s
* @param {number} age age in years
* @param {string} gender gender
* @return {number} PTI (Personal Temperature Index)
*/
function calculatePersonalTempIndex(
temp = 20,
humidity = 70,
windSpeed = 10,
age = 30,
gender = "male" || "female",
weight = 80,
height = 180,
activityLevel = 2
) {
// Calculate baseline temperature index based on personal factors
let baselineIndex = 20;
baselineIndex += age / 60;
baselineIndex += gender === "male" ? 1 : 0;
baselineIndex -= weight / 50;
baselineIndex -= height <= 160 ? Math.floor((160 - height) / 10) : 0;
baselineIndex += activityLevel;
const heatIndex = (tempCelsius, humidity) =>
tempCelsius >= 26
? -8.78469475556 +
1.61139411 * tempCelsius +
2.33854883889 * humidity -
0.14611605 * tempCelsius * humidity -
0.012308094 * tempCelsius ** 2 -
0.0164248277778 * humidity ** 2 +
0.002211732 * tempCelsius ** 2 * humidity +
0.00072546 * tempCelsius * humidity ** 2 -
0.000003582 * tempCelsius ** 2 * humidity ** 2
: tempCelsius;
baselineIndex += temp >= 26 ? heatIndex / 10 : 0;
// Adjust for external factors
baselineIndex -= Math.floor(humidity / 80);
baselineIndex -= Math.floor(windSpeed / 15);

// Calculate final personal temperature index
let personalIndex = baselineIndex + (temp - 20) / 5;
return personalIndex;
}
//TODO: Add weather alerts
moment.locale(Localization.locale.slice(0, 2));

export default function CurrentScreen({ weather, location, t }) {
//const theme = useTheme();
Expand Down Expand Up @@ -160,10 +115,11 @@ export default function CurrentScreen({ weather, location, t }) {
}}
>
{" " +
calculatePTI({
temperature: weather.daily[0].temp.min - 273.15,
calculatePTIOWM({
temp: weather.daily[0].temp.min,
feels_like: weather.daily[0].feels_like.min,
humidity: weather.daily[0].humidity,
windSpeed: weather.daily[0].wind_speed,
wind_speed: weather.daily[0].wind_speed,
}).toFixed(1) +
" " +
t("pti") +
Expand Down Expand Up @@ -200,10 +156,11 @@ export default function CurrentScreen({ weather, location, t }) {
}}
>
{" " +
calculatePTI({
temperature: weather.daily[0].temp.max - 273.15,
calculatePTIOWM({
temp: weather.daily[0].temp.max,
feels_like: weather.daily[0].feels_like.max,
humidity: weather.daily[0].humidity,
windSpeed: weather.daily[0].wind_speed,
wind_speed: weather.daily[0].wind_speed,
}).toFixed(1) +
" " +
t("pti") +
Expand Down
90 changes: 81 additions & 9 deletions components/HourlyScreen.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,81 @@
import React, { useState, useEffect } from 'react';
import { Text, View, ScrollView } from 'react-native';
import { createMaterialBottomTabNavigator as createBottomTabNavigator } from '@react-navigation/material-bottom-tabs';
import { NavigationContainer } from '@react-navigation/native';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { IconButton, Searchbar } from 'react-native-paper';
export default function HourlyScreen({ weather }) {
return null;
}
import React, { useState, useEffect } from "react";
import { View, ScrollView, StyleSheet } from "react-native";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import iconMap from "./iconMap";
import { Text, ActivityIndicator, Divider, MD3LightTheme } from "react-native-paper";
import { calculatePTI } from "./utils/PTI";
import TopCurrent from "./components/TopCurrent";
import { FlexiCard } from "./components/Cards";
import moment from "moment";
import "moment/min/locales";
import HourlyElement from "./components/HourlyElement";
import * as Localization from "expo-localization";
import { RainComponent, UmbrellaIconReactive } from "./components/Bars";
//TODO: Add weather alerts
moment.locale(Localization.locale.slice(0,2));

export default function HourlyScreen({ weather, location, t }) {
//const theme = useTheme();
const theme = {
...MD3LightTheme,
};
const [weatherIcon, setWeatherIcon] = useState("help");
const [weatherIconColor, setWeatherIconColor] = useState(
theme.dark ? iconMap["01d"].color_dark : iconMap["01d"].color
);
useEffect(() => {
if (weather !== {} && weather.current !== undefined) {
console.log(weatherIcon);
setWeatherIcon(
iconMap[weather.current.weather[0].icon].icon !== undefined
? iconMap[weather.current.weather[0].icon].icon
: "help"
);
setWeatherIconColor(
theme.dark
? iconMap[weather.current.weather[0].icon].color_dark !== undefined
? iconMap[weather.current.weather[0].icon].color_dark
: "00FFFF"
: iconMap[weather.current.weather[0].icon].color !== undefined
? iconMap[weather.current.weather[0].icon].color
: "#FF0000"
);
}
});

return weather.hourly !== undefined ? (
<ScrollView
style={{
padding: 8,
backgroundColor: theme.colors.background,
display: "flex",
marginBottom: 16,
}}
>
{
weather.hourly.map((x, index) => {

return <HourlyElement x={x} key={index} theme={theme} t={t} />
})
}
</ScrollView>
) : (
<View
style={{
display: "flex",
flex: 1,
alignContent: "center",
justifyContent: "center",
}}
>
<ActivityIndicator size="large" color={theme.colors.primary} />
</View>
);
}
const styles = StyleSheet.create({
border: {
borderWidth: 1,
borderColor: "#CAC4D0",
borderRadius: 16,
},
});
Loading

0 comments on commit 79fbf37

Please sign in to comment.