Skip to content
Snippets Groups Projects
Commit 89a9dae1 authored by Shrey Patel's avatar Shrey Patel
Browse files

added new chart for stats by member count

parent 24450810
No related branches found
No related tags found
No related merge requests found
...@@ -4,16 +4,18 @@ import { Chart } from "react-google-charts"; ...@@ -4,16 +4,18 @@ import { Chart } from "react-google-charts";
export const OrgChart = () => { export const OrgChart = () => {
const [info, setInfo] = useState(); const [info, setInfo] = useState();
const [infoForMemberChart, setInfoForMemberChart] = useState();
useEffect(() => { useEffect(() => {
// Fetch user information when the component mounts // Fetch user information when the component mounts
getOrgStats(); getOrgStats();
getOrgStatsByMember();
}, []); // Empty dependency array ensures the effect runs once }, []); // Empty dependency array ensures the effect runs once
const getOrgStats = async () => { const getOrgStats = async () => {
try { try {
const response = await Axios.get( const response = await Axios.get(
"http://localhost:8080/organization/all/stats" "http://localhost:8080/organization/all/stats/category"
); );
const some = [["Task", "Hours per Day"], ...response.data.data]; const some = [["Task", "Hours per Day"], ...response.data.data];
setInfo(some); setInfo(some);
...@@ -22,18 +24,43 @@ export const OrgChart = () => { ...@@ -22,18 +24,43 @@ export const OrgChart = () => {
} }
}; };
const options = { const getOrgStatsByMember = async () => {
try {
const response = await Axios.get(
"http://localhost:8080/organization/all/stats/members"
);
const some = [["Task", "Hours per Day"], ...response.data.data];
setInfoForMemberChart(some);
} catch (error) {
console.error("Error fetching stats:", error);
}
};
const options1 = {
title: "Organizations by Category", title: "Organizations by Category",
}; };
const options2 = {
title: "Organizations by Popularity",
};
return ( return (
<Chart <div>
chartType="PieChart" <Chart
data={info} chartType="PieChart"
options={options} data={info}
width={"100%"} options={options1}
height={"400px"} width={"100%"}
/> height={"400px"}
/>
<Chart
chartType="PieChart"
data={infoForMemberChart}
options={options2}
width={"100%"}
height={"400px"}
/>
</div>
); );
}; };
export default OrgChart; export default OrgChart;
...@@ -24,12 +24,12 @@ public class CustomOrganizationRepository ...@@ -24,12 +24,12 @@ public class CustomOrganizationRepository
return (List<Object[]>)q.getResultList(); return (List<Object[]>)q.getResultList();
} }
// @Transactional @Transactional
// public List<Object[]> countOrganizationsByMemberCount() public List<Object[]> countOrganizationsByMemberCount()
// { {
// String query = "SELECT category, COUNT(*) FROM Organization GROUP BY category"; String query = "SELECT category, SUM(member_count) AS total_members FROM ORGANIZATION GROUP BY category;";
// Query q = this.entityManager.createNativeQuery(query); Query q = this.entityManager.createNativeQuery(query);
// return (List<Object[]>)q.getResultList(); return (List<Object[]>)q.getResultList();
// } }
} }
\ No newline at end of file
...@@ -44,8 +44,8 @@ public class OrgController { ...@@ -44,8 +44,8 @@ public class OrgController {
return orgRepository.findAll(); return orgRepository.findAll();
} }
@GetMapping(path="/all/stats") @GetMapping(path="/all/stats/category")
public @ResponseBody Map<String, Object> getAllOrgStats() { public @ResponseBody Map<String, Object> getAllOrgStatsByCategory() {
// This returns a JSON with statistics about how many organziations are in each category // This returns a JSON with statistics about how many organziations are in each category
List<Object[]> categoryCounts = customOrganizationRepository.countOrganizationsByCategory(); List<Object[]> categoryCounts = customOrganizationRepository.countOrganizationsByCategory();
Map<String, Object> response = new HashMap<>(); Map<String, Object> response = new HashMap<>();
...@@ -58,4 +58,18 @@ public class OrgController { ...@@ -58,4 +58,18 @@ public class OrgController {
return response; return response;
} }
@GetMapping(path="/all/stats/members")
public @ResponseBody Map<String, Object> getAllOrgStatsByMembers() {
// This returns a JSON with statistics about how many organziations are in each category
List<Object[]> categoryCounts = customOrganizationRepository.countOrganizationsByMemberCount();
Map<String, Object> response = new HashMap<>();
// for (Object[] row : categoryCounts) {
// Organization.Category category = (Organization.Category) row[0];
// Long count = (Long) row[1];
// stats.put(category.toString(), count);
// }
response.put("data", categoryCounts);
return response;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment