-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
235 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package repository | ||
|
||
import "gorm.io/gorm" | ||
|
||
type ContainerWithSize struct { | ||
Container string `json:"container"` | ||
Size int `json:"size"` | ||
} | ||
|
||
func GetOSFilesSeparatedByContainers(db *gorm.DB) ([]*ContainerWithSize, error) { | ||
var files []*ContainerWithSize | ||
|
||
result := db.Raw(`select container, file_size as size from os_files group by container`).Scan(&files) | ||
return files, result.Error | ||
} | ||
|
||
func GetSizeDiff(db *gorm.DB) (map[string]int64, error) { | ||
var files struct { | ||
TotalFileSize int64 `json:"total_file_size"` | ||
UniqueFileSize int64 `json:"unique_file_size"` | ||
} | ||
|
||
err := db.Raw(` | ||
select sum(os_files.file_size) AS total_file_size, sum(DISTINCT os_files.file_size) AS unique_file_size | ||
from files join os_files ON os_files.id = files.os_file_id | ||
`).Scan(&files).Error | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return map[string]int64{ | ||
"total_file_size": files.TotalFileSize, | ||
"unique_file_size": files.UniqueFileSize, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<template> | ||
<template v-if="d != null"> | ||
<h2 class="fredoka text-2xl">Analytics</h2> | ||
<section class="md:grid md:grid-cols-2 md:gap-2"> | ||
<div class="p-2 mt-2 rounded-lg bg-widget"> | ||
<diff-chart :diff="d?.file_difference" /> | ||
</div> | ||
<div class="p-2 mt-2 rounded-lg bg-widget"> | ||
<container-chart :containers="d?.os_file_container" /> | ||
</div> | ||
</section> | ||
</template> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import DiffChart from "~/components/admin/diff-chart.vue"; | ||
import type {Analytics} from "~/types/analytics"; | ||
import {fetchAnalytics} from "~/scripts/analytics"; | ||
import {useLoaderStore} from "#imports"; | ||
import ContainerChart from "~/components/admin/container-chart.vue"; | ||
const loader = useLoaderStore() | ||
const d = ref<Analytics|null>(null) | ||
onMounted(async () => { | ||
loader.start() | ||
const res = await fetchAnalytics() | ||
if(!res) return | ||
d.value = res | ||
loader.finish() | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<script setup lang="ts"> | ||
import type {Containers} from "~/types/analytics"; | ||
import { Pie } from 'vue-chartjs' | ||
const props = defineProps<{ | ||
containers: Containers | ||
}>() | ||
const getLightColor = () => { | ||
let letters = 'BCDEF'.split(''); | ||
let color = '#'; | ||
for (let i = 0; i < 6; i++ ) { | ||
color += letters[Math.floor(Math.random() * letters.length)]; | ||
} | ||
return color; | ||
} | ||
const getColors = (n: number): Array<string> => { | ||
let colors = [] | ||
for(let i = 0; i < n; i++) { | ||
colors.push(getLightColor()) | ||
} | ||
return colors | ||
} | ||
const chartData = ref({ | ||
labels: [...props.containers.map(c => c.container)], | ||
datasets: [ | ||
{ | ||
label: 'Bytes', | ||
backgroundColor: [...getColors(props.containers.length)], | ||
data: [...props.containers.map(c => c.size)], | ||
}, | ||
], | ||
}) | ||
const chartOptions = ref({ | ||
responsive: true, | ||
maintainAspectRatio: false, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<Pie | ||
:data="chartData" | ||
:options="chartOptions" | ||
/> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<script setup lang="ts"> | ||
import type {FileDiff} from "~/types/analytics"; | ||
import { Bar } from 'vue-chartjs' | ||
const props = defineProps<{ | ||
diff: FileDiff | ||
}>() | ||
const chartData = ref({ | ||
labels: ['Total', 'Unique'], | ||
datasets: [ | ||
{ | ||
label: 'Bytes', | ||
backgroundColor: '#847ef7', | ||
data: [props.diff.total_file_size, props.diff.unique_file_size], | ||
}, | ||
], | ||
}) | ||
const chartOptions = ref({ | ||
responsive: true, | ||
maintainAspectRatio: false, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<Bar | ||
:data="chartData" | ||
:options="chartOptions" | ||
/> | ||
</template> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Chart, Title, Tooltip, Legend, BarElement, CategoryScale, LinearScale, ArcElement } from 'chart.js' | ||
|
||
export default defineNuxtPlugin(() => { | ||
Chart.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, ArcElement) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type {Collaborator} from "~/types/user"; | ||
import {newRequest} from "~/scripts/request"; | ||
import type {Analytics} from "~/types/analytics"; | ||
|
||
export const fetchAnalytics = async (): Promise<Analytics | null> => { | ||
try { | ||
const res = await newRequest(`/admin/analytics`); | ||
if (res.status != 200) return null; | ||
const data = await res.json(); | ||
return data as Analytics; | ||
} catch (e: unknown) { | ||
console.error(e); | ||
return null; | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
export interface FileDiff { | ||
total_file_size: number | ||
unique_file_size: number | ||
} | ||
|
||
export type Containers = Array<{ | ||
container: string | ||
size: number | ||
}> | ||
|
||
export interface Analytics { | ||
file_difference: FileDiff | ||
os_file_container: Containers | ||
} |