Addded initial heatmap rendering

This commit is contained in:
Keannu Bernasol 2023-09-06 18:13:43 +08:00
parent 15b14a32e8
commit 058b120ce9
3 changed files with 158 additions and 7 deletions

View file

@ -17,7 +17,7 @@ if (__DEV__) {
}
// Switch this on if you wanna run production URLs while in development
let use_production = true;
let use_production = false;
if (__DEV__ && use_production) {
backendURL = "https://stude.keannu1.duckdns.org";
backendURLWebsocket = "ws://stude.keannu1.duckdns.org";
@ -269,3 +269,30 @@ export async function GetStudentStatusList() {
return [false, error_message];
});
}
export async function GetStudentStatusListFiltered() {
const config = await GetConfig();
return instance
.get("/api/v1/student_status/filter/near_student_status", config)
.then((response) => {
return [true, response.data];
})
.catch((error) => {
let error_message = ParseError(error);
return [false, error_message];
});
}
// To-do
export async function GetStudentStatusListFilteredCurrentLocation() {
const config = await GetConfig();
return instance
.get("/api/v1/student_status/list/", config)
.then((response) => {
return [true, response.data];
})
.catch((error) => {
let error_message = ParseError(error);
return [false, error_message];
});
}

View file

@ -1,5 +1,6 @@
import * as Location from "expo-location";
import { GetStudentStatus } from "../components/Api/Api";
import { Float } from "react-native/Libraries/Types/CodegenTypes";
export interface IconProps {
size: number;
@ -124,8 +125,8 @@ export interface PatchUserInfoType {
}
interface Location {
latitude: number;
longitude: number;
latitude: Float;
longitude: Float;
}
export interface StudentStatusType {
@ -136,9 +137,19 @@ export interface StudentStatusType {
active?: boolean;
}
export interface StudentStatusFilterType {
active: boolean;
distance: number;
landmark: string | null;
location: Location;
study_group?: string;
subject: string;
user: string;
}
export type StudentStatusReturnType = [boolean, StudentStatusType];
export type StudentStatusListType = Array<StudentStatusType>;
export type StudentStatusListType = Array<StudentStatusFilterType>;
export type StudentStatusListReturnType = [boolean, StudentStatusListType];
export type LocationType = Location.LocationObject;

View file

@ -2,7 +2,15 @@ import styles, { Viewport, colors } from "../../styles";
import { View, Text } from "react-native";
import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer";
import { useState, useEffect } from "react";
import MapView, { Callout, Marker, UrlTile } from "react-native-maps";
import MapView, {
Callout,
Heatmap,
Circle,
Marker,
UrlTile,
Overlay,
Polygon,
} from "react-native-maps";
import * as Location from "expo-location";
import GetDistance from "../../components/GetDistance/GetDistance";
import Button from "../../components/Button/Button";
@ -12,11 +20,13 @@ import {
LocationType,
StudentStatusType,
StudentStatusListReturnType,
StudentStatusListType,
} from "../../interfaces/Interfaces";
import { useNavigation } from "@react-navigation/native";
import {
GetStudentStatus,
GetStudentStatusList,
GetStudentStatusListFiltered,
PatchStudentStatus,
urlProvider,
} from "../../components/Api/Api";
@ -166,18 +176,60 @@ export default function Home() {
},
});
const [student_statuses, setStudentStatuses] = useState<any>([]);
// Student Status List
const StudentStatusList = useQuery({
enabled: studying,
queryKey: ["user_status_list"],
queryFn: async () => {
const data = await GetStudentStatusList();
const data = await GetStudentStatusListFiltered();
if (data[0] == false) {
return Promise.reject(new Error(JSON.stringify(data[1])));
}
return data;
},
onSuccess: (data: StudentStatusListReturnType) => {
console.log("List of students:", data[1]);
if (data[1]) {
// We first flatten the data to remove nested entries
let flattened_data = data[1].map((item) => ({
active: item.active,
distance: item.distance,
landmark: item.landmark,
latitude: item.location.latitude,
longitude: item.location.longitude,
study_group: "",
subject: item.subject,
user: item.user,
}));
flattened_data.push({
active: true,
distance: 50,
landmark: "",
latitude: 9.498298904115586,
longitude: 125.59552381187677,
study_group: "",
subject: "Introduction to Computing",
user: "Keannu",
});
// We get each unique subject
let unique_subjects = [
...new Set(flattened_data.map((item) => item.subject)),
];
console.log("Unique Subjects:", unique_subjects);
let result: any[] = [];
// Then append all entries belonging to that subject to its own array
unique_subjects.forEach((subject) => {
let filteredData = flattened_data.filter(
(item) => item.subject === subject && item.study_group === ""
);
// We then concatenate this into the final array
result = result.concat([filteredData]);
});
console.log("Final Result:", result);
setStudentStatuses(result);
}
},
onError: (error: Error) => {
toast.show(String(error), {
@ -222,6 +274,66 @@ export default function Home() {
}}
loadingBackgroundColor={colors.secondary_2}
>
{student_statuses.map((student_status: any, index: number) => {
console.log("TEST INDEX", index, student_status);
return (
<Polygon
key={index}
coordinates={student_status}
fillColor="red"
strokeColor="50"
zIndex={100}
tappable
onPress={() => {
const users = student_statuses.map((item: any) => ({
user: item.user,
}));
toast.hideAll();
toast.show(
<View
style={{
alignContent: "center",
alignSelf: "center",
justifyContent: "center",
}}
>
<Text style={styles.text_white_tiny_bold}>
Subject: {student_status[0].subject}
</Text>
<Text style={styles.text_white_tiny_bold}>
Students Studying: {student_status.length}
</Text>
<Button
onPress={() => {
toast.show("Toledo para ma konsehal", {
type: "warning",
placement: "top",
duration: 2000,
animationType: "slide-in",
});
}}
>
<Text style={styles.text_white_tiny_bold}>
Create Group & Invite
</Text>
</Button>
</View>,
{
type: "normal",
placement: "top",
duration: 2000,
animationType: "slide-in",
style: {
backgroundColor: colors.secondary_2,
borderWidth: 1,
borderColor: colors.primary_1,
},
}
);
}}
/>
);
})}
<UrlTile
urlTemplate={urlProvider}
shouldReplaceMapContent={true}
@ -229,6 +341,7 @@ export default function Home() {
flipY={false}
zIndex={1}
/>
<Marker
coordinate={{
latitude: location.coords.latitude,