This commit is contained in:
Kseninia Mikhaylova 2024-04-24 16:04:58 +03:00
commit 340d908fbe
19 changed files with 5190 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
__pycache__/
data.txt
poetry.lock
front/dist/
front/node_modules/
front/.env
front/components.d.ts
front/src/vite-env.d.ts

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM nikolaik/python-nodejs:latest
ENV WORKING_DIR=/app
# Set the working directory to /app
WORKDIR ${WORKING_DIR}
# Copy the project to the container
COPY . ${WORKING_DIR}
# COPY .env ${WORKING_DIR}
COPY pyproject.toml .
RUN poetry export --without-hashes -f requirements.txt -o requirements.txt
RUN pip install -r requirements.txt
RUN cd front && npm install && npm run build
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]

8
docker-compose.yml Normal file
View File

@ -0,0 +1,8 @@
services:
web:
build:
dockerfile: Dockerfile
env_file:
- .env
ports:
- 8094:80

1
front/.env.development Normal file
View File

@ -0,0 +1 @@
VITE_SERVER = 'http://localhost:8001'

1
front/README.md Normal file
View File

@ -0,0 +1 @@
# Zoo Monitor

13
front/index.html Normal file
View File

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Time Sheet Calendar</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

4884
front/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

28
front/package.json Normal file
View File

@ -0,0 +1,28 @@
{
"name": "front",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"i": "^0.3.7",
"npm": "^10.5.2",
"simpledotcss": "^2.3.0",
"vue": "^3.4.21"
},
"devDependencies": {
"@iconify-json/mdi": "^1.1.66",
"@iconify/vue": "^4.1.1",
"@vitejs/plugin-vue": "^5.0.4",
"sass": "^1.75.0",
"typescript": "^5.2.2",
"unplugin-icons": "^0.18.5",
"unplugin-vue-components": "^0.26.0",
"vite": "^5.2.0",
"vue-tsc": "^2.0.6"
}
}

1
front/public/vite.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

48
front/src/App.vue Normal file
View File

@ -0,0 +1,48 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
const data = ref<ItemType[]>([])
type ItemType = {
"name": string[],
"calendar": string,
"hours": string,
"percent": string
}
const baseUrl = import.meta.env.VITE_SERVER || ''
const numberElement = ref(0)
const item = computed(() => {
if (Object.values(data.value)[numberElement.value]) {
return Object.values(data.value)[numberElement.value]
} else {
return null
}
})
onMounted(async () => {
const res = await fetch(`${baseUrl}/api/sheet`)
const result = await res.json()
if (result.status == "success") {
data.value = result.data
}
setInterval(() => {
if (numberElement.value > Object.values(data.value).length - 2) {
numberElement.value = 0
} else {
numberElement.value += 1
}
}, 3000)
})
</script>
<template>
<div class="item-wrapper">
<div class="item" v-if="item">
{{ item.name.slice(0, 2).join(' ') }}<br />
{{ item.hours }} / {{ Math.ceil(parseFloat(item.calendar)) }}
<strong :class="{
'high': parseInt(item.percent) >= 70,
'medium': parseInt(item.percent) >= 35 && parseInt(item.percent) < 70,
}">({{ item.percent }}%)</strong>
</div>
</div>
</template>

8
front/src/helpers.ts Normal file
View File

@ -0,0 +1,8 @@
export const normalize_count_form = (number: number, words_arr: string[]) => {
number = Math.abs(number);
if (Number.isInteger(number)) {
let options = [2, 0, 1, 1, 1, 2];
return words_arr[(number % 100 > 4 && number % 100 < 20) ? 2 : options[(number % 10 < 5) ? number % 10 : 5]];
}
return words_arr[1];
}

6
front/src/main.ts Normal file
View File

@ -0,0 +1,6 @@
import { createApp } from 'vue'
import 'simpledotcss/simple-v1.min.css'
import './style.scss'
import App from './App.vue'
createApp(App).mount('#app')

30
front/src/style.scss Normal file
View File

@ -0,0 +1,30 @@
body {
background: black;
max-width: 100%;
display: flex;
align-items: center;
justify-content: center;
font-size: 4.5rem;
color: #fff;
}
.item {
flex-shrink: 0;
line-height: 1.2;
&-wrapper {
display: flex;
flex-direction: column;
overflow: hidden;
text-align: center;
}
strong {
&.high {
color: #49FF00;
}
&.medium {
color: #FFE400;
}
}
}

25
front/tsconfig.json Normal file
View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
}

11
front/tsconfig.node.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts"]
}

18
front/vite.config.ts Normal file
View File

@ -0,0 +1,18 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Icons from 'unplugin-icons/vite'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
Components({
resolvers: [
IconsResolver(),
],
}),
Icons()
]
})

59
main.py Normal file
View File

@ -0,0 +1,59 @@
import requests
import os
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(funcName)s %(message)s",
)
logger = logging.getLogger(__name__)
origins = [
"http://localhost",
"http://localhost:4173",
"http://localhost:5173",
"http://localhost:8000",
]
api_app = FastAPI(title="api app")
@api_app.get("/sheet")
async def sheet():
users = {}
with open("data.txt", "r") as filedata:
for line in filedata:
if line.startswith("Исполнитель, Код"):
continue
if line.startswith("Операция"):
continue
if line.startswith("СПЦФ"):
continue
chunk = line.strip().split("\t")
if len(chunk[0].split(" ")) > 3:
name = chunk[0].split(" ")
users[str(name[-1])] = {
"name": name[0:-1],
"calendar": chunk[1],
"hours": chunk[2],
"percent": chunk[3],
}
return {"status": "success", "data": users}
app = FastAPI(title="main app")
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.mount("/api", api_app)
app.mount("/", StaticFiles(directory="front/dist", html=True), name="front")

24
pyproject.toml Normal file
View File

@ -0,0 +1,24 @@
[tool.poetry]
name = "worker-time-sheet"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
package-mode=false
[tool.poetry.dependencies]
python = "^3.10"
uvicorn = "^0.29.0"
requests = "^2.31.0"
fastapi = "^0.110.2"
[tool.poetry.group.dev.dependencies]
taskipy = "^1.12.2"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.taskipy.tasks]
build = "cd front && npm install && npm run build"
start = "uvicorn main:app --reload --port 8001"

0
readme.md Normal file
View File