Skip to content

Commit

Permalink
Fixed part of styling issue #24
Browse files Browse the repository at this point in the history
  • Loading branch information
yaswant2403 committed Nov 21, 2024
1 parent a7faf8f commit d957b1b
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions Project/SafeIllini/app/(tabs)/Statistics.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React, { useState, useEffect } from 'react';
import { View, Text, StyleSheet, ScrollView } from 'react-native';
import { View, Text, StyleSheet, ScrollView, useWindowDimensions, Dimensions } from 'react-native';
import { Picker } from '@react-native-picker/picker';
import { BarChart } from 'react-native-chart-kit';
import { Dimensions } from 'react-native';
import { database } from '../../configs/firebaseConfig'; // Import the Firebase configuration
import { ref, onValue, getDatabase } from 'firebase/database';
import dayjs from 'dayjs';
import { ref, onValue } from 'firebase/database';
import { Dayjs } from 'dayjs';
import { } from 'react-native';

const StatisticsScreen = () => {
//const database = getDatabase();
const { width, height } = useWindowDimensions();
const chartWidth = width * 0.9; // 90% of screen width
const chartHeight = height * 0.3; // 30% of screen height
const [incidents, setIncidents] = useState<Incident[]>([]);
const [selectedSeverity, setSelectedSeverity] = useState<string>('all');
const [selectedTime, setSelectedTime] = useState<string>('all');
Expand All @@ -26,7 +28,7 @@ const StatisticsScreen = () => {
type: string;
photos?: string[];
}

// Update the data fetching logic
useEffect(() => {
const incidentsRef = ref(database, 'incidents');
Expand All @@ -51,40 +53,40 @@ const StatisticsScreen = () => {
setIncidents([]);
}
});

return () => unsubscribe();
}, []);

useEffect(() => {
const now = Date.now();

const filtered = incidents.filter((incident) => {
// Match severity
const matchesSeverity =
selectedSeverity === 'all' || incident.severity === selectedSeverity;

// Match time (assuming 'timeFilters' provides duration in milliseconds)

// Define the timeFilters object at the component level
const timeFilters: Record<string, number> = {
'all': Infinity,
'last 1 hour': 60 * 60 * 1000,
'last 24 hours': 24 * 60 * 60 * 1000,
'last 1 week': 7 * 24 * 60 * 60 * 1000,
'last 1 month': 30 * 24 * 60 * 60 * 1000
};
const timeFilters: Record<string, number> = {
'all': Infinity,
'last 1 hour': 60 * 60 * 1000,
'last 24 hours': 24 * 60 * 60 * 1000,
'last 1 week': 7 * 24 * 60 * 60 * 1000,
'last 1 month': 30 * 24 * 60 * 60 * 1000
};

// Update the time matching logic
const matchesTime =
selectedTime === 'all' ||
(now - incident.timestamp <= timeFilters[selectedTime]);

// Update the time matching logic
const matchesTime =
selectedTime === 'all' ||
(now - incident.timestamp <= timeFilters[selectedTime]);

return matchesSeverity && matchesTime;
});

setFilteredData(filtered);
}, [incidents, selectedSeverity, selectedTime]);


const generateChartData = () => {
const types = ['sexual_harassment', 'drunk_driving', 'theft'];
Expand Down Expand Up @@ -137,9 +139,10 @@ const StatisticsScreen = () => {

<BarChart
data={generateChartData()}
width={outerWidth - 20}
height={220}
width={chartWidth}
height={chartHeight}
yAxisLabel=""
yAxisSuffix=""
chartConfig={{
backgroundColor: '#fff',
backgroundGradientFrom: '#f8f8f8',
Expand Down

0 comments on commit d957b1b

Please sign in to comment.