feat: Add Uziomy calculator page with grounding calculations and document generation
- Implemented Uziomy component for calculating grounding parameters. - Added state management for input fields and results. - Integrated DatePicker for date selection. - Created functions for grounding calculations, document generation (DOCX), and DXF file generation. - Enhanced UI with Tailwind CSS for better styling and responsiveness. - Updated global styles to include Inter font and custom scrollbar styles. - Configured Tailwind CSS to extend colors, fonts, and animations.
This commit is contained in:
339
pages/cross.js
339
pages/cross.js
@@ -1,50 +1,21 @@
|
||||
import Head from "next/head";
|
||||
import { useState, useCallback } from "react";
|
||||
import styles from "../styles/Home.module.css";
|
||||
import Header from "../components/templates/header";
|
||||
import Nav from "../components/templates/nav";
|
||||
import UserTop from "../components/templates/userTop";
|
||||
import Content from "../components/templates/content";
|
||||
import Footer from "../components/templates/footer";
|
||||
import { useSession, signIn, signOut } from "next-auth/react";
|
||||
import {
|
||||
Pane,
|
||||
TextInputField,
|
||||
TextareaField,
|
||||
Button,
|
||||
BuildIcon,
|
||||
toaster,
|
||||
Alert,
|
||||
import { useSession, signIn } from "next-auth/react";
|
||||
import Layout from "../components/ui/Layout";
|
||||
import { Card, CardHeader, CardContent, CardTitle, CardDescription, Button, Alert } from "../components/ui/components";
|
||||
import {
|
||||
FileUploader,
|
||||
FilePicker,
|
||||
FileCard,
|
||||
} from "evergreen-ui";
|
||||
import { CloudArrowUpIcon as CloudUploadIcon, ArrowDownTrayIcon as DownloadIcon, Squares2X2Icon as GridIcon } from '@heroicons/react/24/outline';
|
||||
import axios from "axios";
|
||||
|
||||
export default function Cross() {
|
||||
const { data: session } = useSession();
|
||||
|
||||
const [fileData, setFileData] = useState(null);
|
||||
const handleDownload = () => {
|
||||
console.log("down");
|
||||
if (fileData) {
|
||||
console.log("load");
|
||||
// const link = document.createElement("a");
|
||||
// link.href = `data:application/octet-stream;base64,${fileData}`;
|
||||
// link.download = "plik.dxf";
|
||||
// link.click();
|
||||
document.getElementById("down").download = fileData.filename;
|
||||
console.log(fileData.filename)
|
||||
|
||||
document.getElementById("down").href = "cross.dxf";
|
||||
console.log("cross.dxf")
|
||||
|
||||
document.getElementById("down").click();
|
||||
}
|
||||
};
|
||||
|
||||
const [files, setFiles] = useState([]);
|
||||
const [fileRejections, setFileRejections] = useState([]);
|
||||
const [fileData, setFileData] = useState(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const handleChange = useCallback((files) => setFiles([files[0]]), []);
|
||||
const handleRejected = useCallback(
|
||||
(fileRejections) => setFileRejections([fileRejections[0]]),
|
||||
@@ -55,136 +26,222 @@ export default function Cross() {
|
||||
setFileRejections([]);
|
||||
}, []);
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
let file = files[0];
|
||||
|
||||
if (!file) {
|
||||
// Handle error if no file is selected
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
setIsLoading(true);
|
||||
|
||||
console.log("Files:", files);
|
||||
if (files.length === 0) {
|
||||
console.log("No files selected");
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("files", files[0]);
|
||||
|
||||
axios
|
||||
.post("/api/upload", formData, {
|
||||
.post("/api/cross", formData, {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response.data);
|
||||
if (response.data.toString().startsWith("Py Error")) {
|
||||
toaster.danger(response.data);
|
||||
return;
|
||||
}
|
||||
toaster.warning(response.statusText);
|
||||
console.log(response.data)
|
||||
setFileData(response.data);
|
||||
document.getElementById("download").disabled = false;
|
||||
|
||||
// document.getElementById("down").download =
|
||||
// response.data.filename.toString().split(".")[0].split("-")[1]+"_s.dxf";
|
||||
// document.getElementById("down").href =
|
||||
// "uploads/"+response.data.filename.toString().split(".")[0]+"_s.dxf";
|
||||
// document.getElementById("down").click();
|
||||
setIsLoading(false);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
setIsLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
const handleDownload = () => {
|
||||
if (fileData) {
|
||||
document.getElementById("down").download = fileData.filename;
|
||||
document.getElementById("down").href = "cross.dxf";
|
||||
document.getElementById("down").click();
|
||||
}
|
||||
};
|
||||
|
||||
if (session) {
|
||||
return (
|
||||
<div className="">
|
||||
<Head>
|
||||
<title>Wastpol</title>
|
||||
</Head>
|
||||
<Layout title="Wastpol - Generator siatki">
|
||||
<div className="p-6 max-w-4xl mx-auto">
|
||||
{/* Page Header */}
|
||||
<div className="mb-8">
|
||||
<div className="flex items-center space-x-3 mb-4">
|
||||
<div className="p-3 bg-blue-100 rounded-lg">
|
||||
<GridIcon className="w-8 h-8 text-blue-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold text-gray-900">Generator siatki</h1>
|
||||
<p className="text-gray-600">Przekształć pliki DXF na siatki instalacyjne</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex md:flex-row flex-col justify-between px-8 mt-2">
|
||||
<Nav />
|
||||
<UserTop session={session} />
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
||||
{/* Upload Section */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center space-x-2">
|
||||
<CloudUploadIcon className="w-5 h-5 text-blue-600" />
|
||||
<span>Prześlij plik</span>
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Wybierz plik DXF do przetworzenia (maksymalnie 50 MB)
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
<FileUploader
|
||||
label="Przeciągnij i upuść plik lub kliknij aby wybrać"
|
||||
description="Obsługiwane formaty: DXF (max 50 MB)"
|
||||
maxSizeInBytes={50 * 1024 ** 2}
|
||||
maxFiles={1}
|
||||
onChange={handleChange}
|
||||
onRejected={handleRejected}
|
||||
renderFile={(file) => {
|
||||
const { name, size, type } = file;
|
||||
const fileRejection = fileRejections.find(
|
||||
(fileRejection) => fileRejection.file === file
|
||||
);
|
||||
const { message } = fileRejection || {};
|
||||
return (
|
||||
<FileCard
|
||||
key={name}
|
||||
isInvalid={fileRejection != null}
|
||||
name={name}
|
||||
onRemove={handleRemove}
|
||||
sizeInBytes={size}
|
||||
type={type}
|
||||
validationMessage={message}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
values={files}
|
||||
/>
|
||||
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
disabled={files.length === 0 || isLoading}
|
||||
loading={isLoading}
|
||||
className="w-full"
|
||||
>
|
||||
{isLoading ? 'Przetwarzanie...' : 'Dodaj siatkę'}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Results Section */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center space-x-2">
|
||||
<DownloadIcon className="w-5 h-5 text-green-600" />
|
||||
<span>Wynik</span>
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Pobierz wygenerowany plik siatki
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{fileData ? (
|
||||
<div className="space-y-4">
|
||||
<Alert variant="success">
|
||||
<div className="flex items-center space-x-2">
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
<span>Plik został pomyślnie przetworzony!</span>
|
||||
</div>
|
||||
</Alert>
|
||||
|
||||
<Button
|
||||
onClick={handleDownload}
|
||||
variant="primary"
|
||||
className="w-full"
|
||||
>
|
||||
<DownloadIcon className="w-5 h-5 mr-2" />
|
||||
Pobierz siatką DXF
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-8">
|
||||
<div className="mx-auto w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mb-4">
|
||||
<GridIcon className="w-8 h-8 text-gray-400" />
|
||||
</div>
|
||||
<p className="text-gray-500">Prześlij plik aby rozpocząć przetwarzanie</p>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Instructions */}
|
||||
<Card className="mt-8">
|
||||
<CardHeader>
|
||||
<CardTitle>Instrukcje</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-sm font-semibold text-blue-600">1</span>
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="font-medium text-gray-900">Prześlij plik</h4>
|
||||
<p className="text-sm text-gray-600">Wybierz plik DXF z projektem</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-sm font-semibold text-blue-600">2</span>
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="font-medium text-gray-900">Przetwarzaj</h4>
|
||||
<p className="text-sm text-gray-600">Kliknij "Dodaj siatkę"</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-sm font-semibold text-blue-600">3</span>
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="font-medium text-gray-900">Pobierz</h4>
|
||||
<p className="text-sm text-gray-600">Zapisz gotową siatkę DXF</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<a href="the.dxf" download="the.dxf" id="down" className="hidden" />
|
||||
</div>
|
||||
|
||||
<main className="flex flex-1 flex-col items-center">
|
||||
<FileUploader
|
||||
label="Prześlij plik"
|
||||
description="Możesz dodać 1 plik, max 50 MB."
|
||||
maxSizeInBytes={50 * 1024 ** 2}
|
||||
maxFiles={1}
|
||||
onChange={handleChange}
|
||||
onRejected={handleRejected}
|
||||
renderFile={(file) => {
|
||||
const { name, size, type } = file;
|
||||
const fileRejection = fileRejections.find(
|
||||
(fileRejection) => fileRejection.file === file
|
||||
);
|
||||
const { message } = fileRejection || {};
|
||||
return (
|
||||
<FileCard
|
||||
key={name}
|
||||
isInvalid={fileRejection != null}
|
||||
name={name}
|
||||
onRemove={handleRemove}
|
||||
sizeInBytes={size}
|
||||
type={type}
|
||||
validationMessage={message}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
values={files}
|
||||
/>
|
||||
|
||||
<Button
|
||||
marginY={8}
|
||||
marginRight={12}
|
||||
appearance="default"
|
||||
iconAfter={BuildIcon}
|
||||
onClick={(e) => {
|
||||
console.log("louding begins");
|
||||
console.log(files);
|
||||
document.getElementById("download").disabled = false;
|
||||
handleSubmit(e);
|
||||
}}
|
||||
>
|
||||
Dodaj siatkę
|
||||
</Button>
|
||||
<Button
|
||||
id="download"
|
||||
marginY={8}
|
||||
marginRight={12}
|
||||
appearance="default"
|
||||
iconAfter={BuildIcon}
|
||||
// disabled={true}
|
||||
onClick={handleDownload}
|
||||
>
|
||||
Pobierz
|
||||
</Button>
|
||||
<a href="the.dxf" download="the.dxf" id="down">
|
||||
{" "}
|
||||
</a>
|
||||
</main>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid place-items-center h-screen">
|
||||
<Head>
|
||||
<title>Wastpol</title>
|
||||
</Head>
|
||||
<div className="flex flex-col justify-center">
|
||||
<h2 className="p-2">Nie zalogowano</h2>
|
||||
<br></br>
|
||||
<Button
|
||||
onClick={() => signIn()}
|
||||
appearance="primary"
|
||||
// className="p-2 bg-slate-200 rounded-md"
|
||||
>
|
||||
Zaloguj
|
||||
</Button>
|
||||
</div>
|
||||
<div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
<CardHeader className="text-center">
|
||||
<div className="mx-auto w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mb-4">
|
||||
<img src="/logo.png" alt="Wastpol" className="w-10 h-10" />
|
||||
</div>
|
||||
<CardTitle className="text-2xl">Zaloguj się</CardTitle>
|
||||
<p className="text-gray-600 mt-2">Uzyskaj dostęp do generatora siatki</p>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Button onClick={() => signIn()} className="w-full" size="lg">
|
||||
Zaloguj się
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
247
pages/cross_new.js
Normal file
247
pages/cross_new.js
Normal file
@@ -0,0 +1,247 @@
|
||||
import { useState, useCallback } from "react";
|
||||
import { useSession, signIn } from "next-auth/react";
|
||||
import Layout from "../components/ui/Layout";
|
||||
import { Card, CardHeader, CardContent, CardTitle, CardDescription, Button, Alert } from "../components/ui/components";
|
||||
import {
|
||||
FileUploader,
|
||||
FileCard,
|
||||
} from "evergreen-ui";
|
||||
import { CloudArrowUpIcon as CloudUploadIcon, ArrowDownTrayIcon as DownloadIcon, Squares2X2Icon as GridIcon } from '@heroicons/react/24/outline';
|
||||
import axios from "axios";
|
||||
|
||||
export default function Cross() {
|
||||
const { data: session } = useSession();
|
||||
const [files, setFiles] = useState([]);
|
||||
const [fileRejections, setFileRejections] = useState([]);
|
||||
const [fileData, setFileData] = useState(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const handleChange = useCallback((files) => setFiles([files[0]]), []);
|
||||
const handleRejected = useCallback(
|
||||
(fileRejections) => setFileRejections([fileRejections[0]]),
|
||||
[]
|
||||
);
|
||||
const handleRemove = useCallback(() => {
|
||||
setFiles([]);
|
||||
setFileRejections([]);
|
||||
}, []);
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
setIsLoading(true);
|
||||
|
||||
console.log("Files:", files);
|
||||
if (files.length === 0) {
|
||||
console.log("No files selected");
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("files", files[0]);
|
||||
|
||||
axios
|
||||
.post("/api/cross", formData, {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response.data);
|
||||
setFileData(response.data);
|
||||
setIsLoading(false);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
setIsLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
const handleDownload = () => {
|
||||
if (fileData) {
|
||||
document.getElementById("down").download = fileData.filename;
|
||||
document.getElementById("down").href = "cross.dxf";
|
||||
document.getElementById("down").click();
|
||||
}
|
||||
};
|
||||
|
||||
if (session) {
|
||||
return (
|
||||
<Layout title="Wastpol - Generator siatki">
|
||||
<div className="p-6 max-w-4xl mx-auto">
|
||||
{/* Page Header */}
|
||||
<div className="mb-8">
|
||||
<div className="flex items-center space-x-3 mb-4">
|
||||
<div className="p-3 bg-blue-100 rounded-lg">
|
||||
<GridIcon className="w-8 h-8 text-blue-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold text-gray-900">Generator siatki</h1>
|
||||
<p className="text-gray-600">Przekształć pliki DXF na siatki instalacyjne</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
||||
{/* Upload Section */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center space-x-2">
|
||||
<CloudUploadIcon className="w-5 h-5 text-blue-600" />
|
||||
<span>Prześlij plik</span>
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Wybierz plik DXF do przetworzenia (maksymalnie 50 MB)
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-4">
|
||||
<FileUploader
|
||||
label="Przeciągnij i upuść plik lub kliknij aby wybrać"
|
||||
description="Obsługiwane formaty: DXF (max 50 MB)"
|
||||
maxSizeInBytes={50 * 1024 ** 2}
|
||||
maxFiles={1}
|
||||
onChange={handleChange}
|
||||
onRejected={handleRejected}
|
||||
renderFile={(file) => {
|
||||
const { name, size, type } = file;
|
||||
const fileRejection = fileRejections.find(
|
||||
(fileRejection) => fileRejection.file === file
|
||||
);
|
||||
const { message } = fileRejection || {};
|
||||
return (
|
||||
<FileCard
|
||||
key={name}
|
||||
isInvalid={fileRejection != null}
|
||||
name={name}
|
||||
onRemove={handleRemove}
|
||||
sizeInBytes={size}
|
||||
type={type}
|
||||
validationMessage={message}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
values={files}
|
||||
/>
|
||||
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
disabled={files.length === 0 || isLoading}
|
||||
loading={isLoading}
|
||||
className="w-full"
|
||||
>
|
||||
{isLoading ? 'Przetwarzanie...' : 'Dodaj siatkę'}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Results Section */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center space-x-2">
|
||||
<DownloadIcon className="w-5 h-5 text-green-600" />
|
||||
<span>Wynik</span>
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Pobierz wygenerowany plik siatki
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{fileData ? (
|
||||
<div className="space-y-4">
|
||||
<Alert variant="success">
|
||||
<div className="flex items-center space-x-2">
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
<span>Plik został pomyślnie przetworzony!</span>
|
||||
</div>
|
||||
</Alert>
|
||||
|
||||
<Button
|
||||
onClick={handleDownload}
|
||||
variant="primary"
|
||||
className="w-full"
|
||||
>
|
||||
<DownloadIcon className="w-5 h-5 mr-2" />
|
||||
Pobierz siatką DXF
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-8">
|
||||
<div className="mx-auto w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mb-4">
|
||||
<GridIcon className="w-8 h-8 text-gray-400" />
|
||||
</div>
|
||||
<p className="text-gray-500">Prześlij plik aby rozpocząć przetwarzanie</p>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Instructions */}
|
||||
<Card className="mt-8">
|
||||
<CardHeader>
|
||||
<CardTitle>Instrukcje</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-sm font-semibold text-blue-600">1</span>
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="font-medium text-gray-900">Prześlij plik</h4>
|
||||
<p className="text-sm text-gray-600">Wybierz plik DXF z projektem</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-sm font-semibold text-blue-600">2</span>
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="font-medium text-gray-900">Przetwarzaj</h4>
|
||||
<p className="text-sm text-gray-600">Kliknij "Dodaj siatkę"</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-sm font-semibold text-blue-600">3</span>
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="font-medium text-gray-900">Pobierz</h4>
|
||||
<p className="text-sm text-gray-600">Zapisz gotową siatkę DXF</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<a href="the.dxf" download="the.dxf" id="down" className="hidden" />
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
<CardHeader className="text-center">
|
||||
<div className="mx-auto w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mb-4">
|
||||
<img src="/logo.png" alt="Wastpol" className="w-10 h-10" />
|
||||
</div>
|
||||
<CardTitle className="text-2xl">Zaloguj się</CardTitle>
|
||||
<p className="text-gray-600 mt-2">Uzyskaj dostęp do generatora siatki</p>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Button onClick={() => signIn()} className="w-full" size="lg">
|
||||
Zaloguj się
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
191
pages/index.js
191
pages/index.js
@@ -1,93 +1,130 @@
|
||||
import Head from "next/head";
|
||||
import styles from "../styles/Home.module.css";
|
||||
import Header from "../components/templates/header";
|
||||
import { useState } from "react";
|
||||
import { useSession, signIn } from "next-auth/react";
|
||||
import Layout from "../components/ui/Layout";
|
||||
import { Card, CardHeader, CardContent, CardTitle, Button, Tabs, TabsTrigger, TabsContent } from "../components/ui/components";
|
||||
import Generator from "../components/templates/generator";
|
||||
import Manual from "../components/templates/manual";
|
||||
import Nav from "../components/templates/nav";
|
||||
import UserTop from "../components/templates/userTop";
|
||||
import Footer from "../components/templates/footer";
|
||||
import { useState } from "react";
|
||||
import { useSession, signIn, signOut } from "next-auth/react";
|
||||
import { Pane, Button, Tab, Tablist } from "evergreen-ui";
|
||||
import { ChartBarIcon, PencilIcon, ArrowRightOnRectangleIcon as LoginIcon } from '@heroicons/react/24/outline';
|
||||
|
||||
export default function Home() {
|
||||
const { data: session } = useSession();
|
||||
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||
const [tabs] = useState(["auto", "manual"]);
|
||||
const [realTabs] = useState([Generator, Manual]);
|
||||
const [selectedTab, setSelectedTab] = useState(0);
|
||||
|
||||
if (session) {
|
||||
return (
|
||||
<div className="">
|
||||
<Head>
|
||||
<title>Wastpol</title>
|
||||
</Head>
|
||||
|
||||
<div className="flex md:flex-row flex-col justify-between px-8 mt-2">
|
||||
<Nav />
|
||||
<UserTop session={session} />
|
||||
</div>
|
||||
|
||||
<main className="flex flex-1 flex-col items-center">
|
||||
<div className="flex flex-col items-center p-8 mt-12 rounded-md shadow-md transition-all duration-500 hover:shadow-xl">
|
||||
<Header />
|
||||
<Tablist>
|
||||
{tabs.map((tab, index) => (
|
||||
<Tab
|
||||
key={tab}
|
||||
id={tab}
|
||||
onSelect={() => setSelectedIndex(index)}
|
||||
isSelected={index === selectedIndex}
|
||||
>
|
||||
{tab}
|
||||
</Tab>
|
||||
))}
|
||||
</Tablist>
|
||||
<Pane>
|
||||
{realTabs.map((tab, index) =>
|
||||
index == 1 ? (
|
||||
<Pane
|
||||
key={tab}
|
||||
id={`panel-${tab}`}
|
||||
role="tabpanel"
|
||||
display={index === selectedIndex ? "block" : "none"}
|
||||
>
|
||||
<Manual />
|
||||
</Pane>
|
||||
) : (
|
||||
<Pane
|
||||
key={tab}
|
||||
id={`panel-${tab}`}
|
||||
role="tabpanel"
|
||||
display={index === selectedIndex ? "block" : "none"}
|
||||
>
|
||||
<Generator />
|
||||
</Pane>
|
||||
)
|
||||
)}
|
||||
</Pane>
|
||||
<Layout title="Wastpol - Profil przekroju terenu">
|
||||
<div className="p-6 max-w-7xl mx-auto">
|
||||
{/* Page Header */}
|
||||
<div className="mb-8">
|
||||
<h1 className="text-3xl font-bold text-gray-900 mb-2">
|
||||
Generator profilu przekroju terenu
|
||||
</h1>
|
||||
<p className="text-gray-600">
|
||||
Twórz profesjonalne profile terenowe na podstawie danych z Geoportalu lub wprowadzonych ręcznie
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
{/* Main Content Card */}
|
||||
<Card className="mb-6">
|
||||
<CardHeader className="border-b bg-gray-50">
|
||||
<Tabs value={selectedTab} onValueChange={setSelectedTab}>
|
||||
<TabsTrigger>
|
||||
<ChartBarIcon className="w-5 h-5 mr-2" />
|
||||
Automatyczny
|
||||
</TabsTrigger>
|
||||
<TabsTrigger>
|
||||
<PencilIcon className="w-5 h-5 mr-2" />
|
||||
Ręczny
|
||||
</TabsTrigger>
|
||||
</Tabs>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="p-0">
|
||||
<TabsContent isActive={selectedTab === 0}>
|
||||
<div className="p-6">
|
||||
<Generator />
|
||||
</div>
|
||||
</TabsContent>
|
||||
<TabsContent isActive={selectedTab === 1}>
|
||||
<div className="p-6">
|
||||
<Manual />
|
||||
</div>
|
||||
</TabsContent>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Info Cards */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
<Card>
|
||||
<CardContent>
|
||||
<div className="flex items-center space-x-3">
|
||||
<div className="p-2 bg-blue-100 rounded-lg">
|
||||
<ChartBarIcon className="w-6 h-6 text-blue-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-semibold text-gray-900">Automatyczny</h3>
|
||||
<p className="text-sm text-gray-600">Import danych z Geoportalu</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardContent>
|
||||
<div className="flex items-center space-x-3">
|
||||
<div className="p-2 bg-green-100 rounded-lg">
|
||||
<PencilIcon className="w-6 h-6 text-green-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-semibold text-gray-900">Ręczny</h3>
|
||||
<p className="text-sm text-gray-600">Wprowadź punkty manualnie</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardContent>
|
||||
<div className="flex items-center space-x-3">
|
||||
<div className="p-2 bg-purple-100 rounded-lg">
|
||||
<svg className="w-6 h-6 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M9 19l3 3m0 0l3-3m-3 3V10" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-semibold text-gray-900">Export DXF</h3>
|
||||
<p className="text-sm text-gray-600">Pobierz gotowy rysunek</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid place-items-center h-screen">
|
||||
<Head>
|
||||
<title>Wastpol</title>
|
||||
</Head>
|
||||
<div className="flex flex-col justify-center">
|
||||
<h2 className="p-2">Nie zalogowano</h2>
|
||||
<br></br>
|
||||
<Button
|
||||
onClick={() => signIn()}
|
||||
appearance="primary"
|
||||
// className="p-2 bg-slate-200 rounded-md"
|
||||
>
|
||||
Zaloguj
|
||||
</Button>
|
||||
</div>
|
||||
<div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
<CardHeader className="text-center">
|
||||
<div className="mx-auto w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mb-4">
|
||||
<img src="/logo.png" alt="Wastpol" className="w-10 h-10" />
|
||||
</div>
|
||||
<CardTitle className="text-2xl">Zaloguj się</CardTitle>
|
||||
<p className="text-gray-600 mt-2">Uzyskaj dostęp do narzędzi inżynierskich</p>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Button
|
||||
onClick={() => signIn()}
|
||||
className="w-full"
|
||||
size="lg"
|
||||
>
|
||||
<LoginIcon className="w-5 h-5 mr-2" />
|
||||
Zaloguj się
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
756
pages/uziomy.js
756
pages/uziomy.js
@@ -1,35 +1,23 @@
|
||||
import Head from "next/head";
|
||||
import styles from "../styles/Home.module.css";
|
||||
import Nav from "../components/templates/nav";
|
||||
import UserTop from "../components/templates/userTop";
|
||||
import { useSession, signIn, signOut } from "next-auth/react";
|
||||
import { useState, useCallback } from "react";
|
||||
import {
|
||||
Pane,
|
||||
TextInputField,
|
||||
TextareaField,
|
||||
Button,
|
||||
BuildIcon,
|
||||
toaster,
|
||||
Alert,
|
||||
FileUploader,
|
||||
FilePicker,
|
||||
FileCard,
|
||||
RadioGroup,
|
||||
Autocomplete,
|
||||
} from "evergreen-ui";
|
||||
|
||||
import PizZip from "pizzip";
|
||||
import Docxtemplater from "docxtemplater";
|
||||
import { useState } from "react";
|
||||
import { useSession, signIn } from "next-auth/react";
|
||||
import Layout from "../components/ui/Layout";
|
||||
import { Card, CardHeader, CardContent, CardTitle, CardDescription, Button, Input, Badge, Alert } from "../components/ui/components";
|
||||
import { BoltIcon as LightningBoltIcon, CalculatorIcon, DocumentArrowDownIcon as DocumentDownloadIcon, ClipboardDocumentListIcon as ClipboardListIcon } from '@heroicons/react/24/outline';
|
||||
import DatePicker from "react-datepicker";
|
||||
import { registerLocale, setDefaultLocale } from "react-datepicker";
|
||||
import { registerLocale } from "react-datepicker";
|
||||
import "react-datepicker/dist/react-datepicker.css";
|
||||
import pl from "date-fns/locale/pl";
|
||||
import PizZip from "pizzip";
|
||||
import Docxtemplater from "docxtemplater";
|
||||
registerLocale("pl", pl);
|
||||
|
||||
export default function Rezy() {
|
||||
export default function Uziomy() {
|
||||
const { data: session } = useSession();
|
||||
const [currentStep, setCurrentStep] = useState(1);
|
||||
const [isCalculating, setIsCalculating] = useState(false);
|
||||
const [isGeneratingDoc, setIsGeneratingDoc] = useState(false);
|
||||
const [isGeneratingDxf, setIsGeneratingDxf] = useState(false);
|
||||
const [calDate, setCalDate] = useState(null);
|
||||
|
||||
const [ground, setGround] = useState({
|
||||
wet_coef: 0,
|
||||
@@ -59,23 +47,6 @@ export default function Rezy() {
|
||||
objName: undefined,
|
||||
});
|
||||
|
||||
// Function to go to the next step
|
||||
const goToNextStep = () => {
|
||||
if (currentStep < 3) {
|
||||
setCurrentStep(currentStep + 1);
|
||||
}
|
||||
};
|
||||
|
||||
// Function to go to the previous step
|
||||
const goToPreviousStep = () => {
|
||||
if (currentStep > 1) {
|
||||
setCurrentStep(currentStep - 1);
|
||||
}
|
||||
};
|
||||
|
||||
const [date, setDate] = useState(null);
|
||||
const [calDate, setCalDate] = useState(null);
|
||||
|
||||
const [options] = useState([
|
||||
{ label: "5 Ω", value: "5" },
|
||||
{ label: "10 Ω", value: "10" },
|
||||
@@ -83,7 +54,6 @@ export default function Rezy() {
|
||||
{ label: "30 Ω", value: "30" },
|
||||
]);
|
||||
const [neededValue, setNeededValue] = useState("5");
|
||||
|
||||
const [resHValue, setResHValue] = useState("88");
|
||||
const [resVValue, setResVValue] = useState("89");
|
||||
|
||||
@@ -100,17 +70,16 @@ export default function Rezy() {
|
||||
}
|
||||
|
||||
function parseDate(dateString) {
|
||||
console.log(dateString);
|
||||
const parts = dateString.split(".");
|
||||
const day = parseInt(parts[0], 10);
|
||||
const month = parseInt(parts[1], 10) - 1; // Months are 0-indexed in JavaScript Dates
|
||||
const month = parseInt(parts[1], 10) - 1;
|
||||
const year = parseInt(parts[2], 10);
|
||||
return new Date(year, month, day);
|
||||
}
|
||||
|
||||
function getGrounding(wanted, wszrg_h, wszrg_v, date) {
|
||||
const dateObject = parseDate(date);
|
||||
const month = dateObject.getMonth() + 1; // JavaScript months are 0-indexed
|
||||
const month = dateObject.getMonth() + 1;
|
||||
|
||||
const wet_coef = month >= 6 && month <= 9 ? 1.2 : 1.6;
|
||||
const rod_len = wanted === 30 ? 2 : 3;
|
||||
@@ -123,53 +92,26 @@ export default function Rezy() {
|
||||
const measure_dist_v = 1 + rod_len;
|
||||
const resistance_v = resistivity_v / (2 * Math.PI * measure_dist_v);
|
||||
|
||||
const result_v =
|
||||
(wszrg_v / (2 * Math.PI * rod_len)) *
|
||||
(Math.log((8 * rod_len) / 0.016) - 1);
|
||||
|
||||
let rod_num = 2; //minimum 2 rods
|
||||
const result_v = (wszrg_v / (2 * Math.PI * rod_len)) * (Math.log((8 * rod_len) / 0.016) - 1);
|
||||
|
||||
let rod_num = 2;
|
||||
let hor_len = 1 + (rod_num - 1) * rod_len * 2;
|
||||
let result_h = (wszrg_h / (2 * Math.PI * hor_len)) * Math.log((hor_len * hor_len) / (1 * 0.0191));
|
||||
|
||||
let result_h =
|
||||
(wszrg_h / (2 * Math.PI * hor_len)) *
|
||||
Math.log((hor_len * hor_len) / (1 * 0.0191));
|
||||
let rod_coef = Math.pow(rod_num, 4) * 0.00002 - Math.pow(rod_num, 3) * 0.0009 +
|
||||
Math.pow(rod_num, 2) * 0.0137 - rod_num * 0.0981 + 1.0468;
|
||||
|
||||
let rod_coef =
|
||||
Math.pow(rod_num, 4) * 0.00002 -
|
||||
Math.pow(rod_num, 3) * 0.0009 +
|
||||
Math.pow(rod_num, 2) * 0.0137 -
|
||||
rod_num * 0.0981 +
|
||||
1.0468;
|
||||
|
||||
let result =
|
||||
(result_v * result_h) /
|
||||
(result_v * rod_coef + rod_num * result_h * rod_coef);
|
||||
let result = (result_v * result_h) / (result_v * rod_coef + rod_num * result_h * rod_coef);
|
||||
|
||||
while (result > wanted) {
|
||||
rod_num += 1;
|
||||
|
||||
hor_len = 1 + (rod_num - 1) * rod_len * 2;
|
||||
|
||||
result_h =
|
||||
(wszrg_h / (2 * Math.PI * hor_len)) *
|
||||
Math.log((hor_len * hor_len) / (1 * 0.0191));
|
||||
|
||||
rod_coef =
|
||||
Math.pow(rod_num, 4) * 0.00002 -
|
||||
Math.pow(rod_num, 3) * 0.0009 +
|
||||
Math.pow(rod_num, 2) * 0.0137 -
|
||||
rod_num * 0.0981 +
|
||||
1.0468;
|
||||
|
||||
result =
|
||||
(result_v * result_h) /
|
||||
(result_v * rod_coef + rod_num * result_h * rod_coef);
|
||||
|
||||
console.log(result, rod_num);
|
||||
result_h = (wszrg_h / (2 * Math.PI * hor_len)) * Math.log((hor_len * hor_len) / (1 * 0.0191));
|
||||
rod_coef = Math.pow(rod_num, 4) * 0.00002 - Math.pow(rod_num, 3) * 0.0009 +
|
||||
Math.pow(rod_num, 2) * 0.0137 - rod_num * 0.0981 + 1.0468;
|
||||
result = (result_v * result_h) / (result_v * rod_coef + rod_num * result_h * rod_coef);
|
||||
}
|
||||
|
||||
console.log(result, rod_num);
|
||||
return {
|
||||
wet_coef: wet_coef,
|
||||
resistivity_h: resistivity_h.toFixed(2),
|
||||
@@ -191,7 +133,24 @@ export default function Rezy() {
|
||||
};
|
||||
}
|
||||
|
||||
const generateDocument = async (ground) => {
|
||||
const calculateGrounding = () => {
|
||||
setIsCalculating(true);
|
||||
try {
|
||||
const res = getGrounding(
|
||||
parseInt(neededValue),
|
||||
parseFloat(resHValue),
|
||||
parseFloat(resVValue),
|
||||
ground.date
|
||||
);
|
||||
setGround((current) => ({ ...current, ...res }));
|
||||
} catch (error) {
|
||||
alert("Błąd podczas obliczeń: " + error.message);
|
||||
}
|
||||
setIsCalculating(false);
|
||||
};
|
||||
|
||||
const generateDocument = async () => {
|
||||
setIsGeneratingDoc(true);
|
||||
const data = {
|
||||
...ground,
|
||||
resisted_object: ground.objValue1 + " " + ground.objName,
|
||||
@@ -200,78 +159,55 @@ export default function Rezy() {
|
||||
try {
|
||||
const response = await fetch("/api/generateDocx", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error: ${response.status}`);
|
||||
}
|
||||
if (!response.ok) throw new Error("Response was not ok.");
|
||||
|
||||
// Convert the response to a blob and download it
|
||||
const blob = await response.blob();
|
||||
const downloadUrl = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = downloadUrl;
|
||||
link.download = "opis.docx";
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
const downloadUrl = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = downloadUrl;
|
||||
a.download = "opis_uziemienia.docx";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
} catch (error) {
|
||||
console.error("Failed to generate document:", error);
|
||||
console.error("Error:", error);
|
||||
alert("Błąd podczas generowania dokumentu");
|
||||
}
|
||||
setIsGeneratingDoc(false);
|
||||
};
|
||||
|
||||
const generateDxf = async () => {
|
||||
// Data that you want to send to the backend
|
||||
var dateParts = ground.date.split(".");
|
||||
setIsGeneratingDxf(true);
|
||||
const dateParts = ground.date.split(".");
|
||||
const month = dateParts[1];
|
||||
const year = parseInt(dateParts[2], 10);
|
||||
const formattedDate = month.padStart(2, "0") + "." + year;
|
||||
|
||||
// Extract day, month, and year
|
||||
var day = parseInt(dateParts[0], 10);
|
||||
var month = parseInt(dateParts[1], 10);
|
||||
var year = parseInt(dateParts[2], 10);
|
||||
|
||||
// Format the result
|
||||
var formattedDate = month.toString().padStart(2, "0") + "." + year;
|
||||
const inputData = {
|
||||
args: [
|
||||
ground.objValue1 + ground.objName,
|
||||
ground.pr_title,
|
||||
ground.object,
|
||||
ground.in_city +
|
||||
", " +
|
||||
ground.commune +
|
||||
", dz. nr " +
|
||||
ground.all_parcels,
|
||||
ground.in_city + ", " + ground.commune + ", dz. nr " + ground.all_parcels,
|
||||
formattedDate,
|
||||
ground.hor_len,
|
||||
ground.rod_len,
|
||||
],
|
||||
};
|
||||
// object1 = args[0] #ZK2a-1P
|
||||
// object2 = args[1] #Budowa przyłącza
|
||||
// object3 = args[2] #Przyłącze kablowe
|
||||
// adres = args[3]
|
||||
// date = args[4]
|
||||
// len_h = int(args[5])
|
||||
// len_v = int(args[6])
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/generateDxf", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(inputData),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Response was not ok.");
|
||||
}
|
||||
if (!response.ok) throw new Error("Response was not ok.");
|
||||
|
||||
// Download the response (the output file)
|
||||
const blob = await response.blob();
|
||||
const downloadUrl = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
@@ -281,271 +217,329 @@ export default function Rezy() {
|
||||
a.click();
|
||||
a.remove();
|
||||
} catch (error) {
|
||||
console.error("There was an error:", error);
|
||||
console.error("Error:", error);
|
||||
alert("Błąd podczas generowania rysunku");
|
||||
}
|
||||
setIsGeneratingDxf(false);
|
||||
};
|
||||
|
||||
if (session) {
|
||||
return (
|
||||
<div className="">
|
||||
<Head>
|
||||
<title>Wastpol</title>
|
||||
</Head>
|
||||
|
||||
<div className="flex md:flex-row flex-col justify-between px-8 mt-2">
|
||||
<Nav />
|
||||
<UserTop session={session} />
|
||||
</div>
|
||||
|
||||
<main className="flex flex-1 flex-col items-center">
|
||||
<div className="flex flex-row m-24 space-x-24">
|
||||
<div>
|
||||
1. Data wykonania pomiaru
|
||||
<br />
|
||||
<br />
|
||||
<b className="m-4">
|
||||
<DatePicker
|
||||
locale="pl"
|
||||
selected={calDate}
|
||||
onChange={(date) => {
|
||||
console.log(date);
|
||||
console.log(typeof date);
|
||||
const day = date.getDate().toString().padStart(2, "0"); // Add leading zero if necessary
|
||||
const month = (date.getMonth() + 1)
|
||||
.toString()
|
||||
.padStart(2, "0"); // Month is 0-indexed, add 1 to get the correct month
|
||||
const year = date.getFullYear();
|
||||
const formattedDate = `${day}.${month}.${year}`;
|
||||
console.log(formattedDate);
|
||||
setGround((current) => ({
|
||||
...current,
|
||||
date: formattedDate,
|
||||
}));
|
||||
setCalDate(date);
|
||||
}}
|
||||
placeholderText="Wybierz datę"
|
||||
dateFormat="dd.MM.yyyy"
|
||||
/>
|
||||
</b>
|
||||
<br />
|
||||
<br />
|
||||
<RadioGroup
|
||||
label="2. Wymagane uziemienie"
|
||||
size={16}
|
||||
value={neededValue}
|
||||
options={options}
|
||||
onChange={(event) => {
|
||||
setNeededValue(event.target.value);
|
||||
}}
|
||||
/>
|
||||
<TextInputField
|
||||
label="3. Rezystywność gruntu (po korekcie wszrg)"
|
||||
description="typowo 80-150"
|
||||
placeholder="86"
|
||||
onChange={(e) => {
|
||||
setResHValue(e.target.value);
|
||||
setResVValue((ground.wanted==30)?
|
||||
getRandomInt(
|
||||
parseInt(e.target.value) - 10,
|
||||
parseInt(e.target.value) - 4
|
||||
):getRandomInt(
|
||||
parseInt(e.target.value) - 20,
|
||||
parseInt(e.target.value) - 10
|
||||
)
|
||||
|
||||
);
|
||||
}}
|
||||
value={resHValue}
|
||||
/>
|
||||
<TextInputField
|
||||
label="4. Numer protokołu rezystywności gruntu"
|
||||
// description=""
|
||||
placeholder="435"
|
||||
onChange={(e) =>
|
||||
setGround((current) => ({ ...current, no: e.target.value }))
|
||||
}
|
||||
value={ground.no}
|
||||
/>{" "}
|
||||
</div>
|
||||
<div>
|
||||
<TextInputField
|
||||
label="5. Tytuł projektu"
|
||||
description="Budowa/modernizacja przyłącza/sieci kablowej/napowietrznej"
|
||||
placeholder="Budowa przyłącza kablowego nN"
|
||||
width={440}
|
||||
onChange={(e) =>
|
||||
setGround((current) => ({
|
||||
...current,
|
||||
pr_title: e.target.value,
|
||||
}))
|
||||
}
|
||||
value={ground.pr_title}
|
||||
/>
|
||||
<TextInputField
|
||||
label="6. Obiekt"
|
||||
// description=""
|
||||
placeholder="Przyłącz kablowy nN"
|
||||
onChange={(e) =>
|
||||
setGround((current) => ({
|
||||
...current,
|
||||
object: e.target.value,
|
||||
}))
|
||||
}
|
||||
value={ground.object}
|
||||
/>
|
||||
<TextInputField
|
||||
label="7. Miejscowość"
|
||||
// description=""
|
||||
placeholder="Paszyn"
|
||||
onChange={(e) =>
|
||||
setGround((current) => ({
|
||||
...current,
|
||||
in_city: e.target.value,
|
||||
}))
|
||||
}
|
||||
value={ground.in_city}
|
||||
/>
|
||||
<TextInputField
|
||||
label="8. Gmina/Obręb"
|
||||
// description=""
|
||||
placeholder="gm. Chełmiec lub obr. 116"
|
||||
onChange={(e) =>
|
||||
setGround((current) => ({
|
||||
...current,
|
||||
commune: e.target.value,
|
||||
}))
|
||||
}
|
||||
value={ground.commune}
|
||||
/>
|
||||
<TextInputField
|
||||
label="9. Działki"
|
||||
// description=""
|
||||
placeholder="Wszystkie numery działek"
|
||||
onChange={(e) =>
|
||||
setGround((current) => ({
|
||||
...current,
|
||||
all_parcels: e.target.value,
|
||||
}))
|
||||
}
|
||||
value={ground.all_parcels}
|
||||
/>
|
||||
<TextInputField
|
||||
label="10. Działka przyłączana"
|
||||
// description=""
|
||||
placeholder="423"
|
||||
onChange={(e) =>
|
||||
setGround((current) => ({
|
||||
...current,
|
||||
target_parcel: e.target.value,
|
||||
}))
|
||||
}
|
||||
value={ground.target_parcel}
|
||||
/>
|
||||
<TextInputField
|
||||
label="11. Współrzędne układu uziomowego"
|
||||
// description=""
|
||||
placeholder={"49°42'54\"N 20°38'0\"E"}
|
||||
onChange={(e) =>
|
||||
setGround((current) => ({
|
||||
...current,
|
||||
geo_data: e.target.value,
|
||||
}))
|
||||
}
|
||||
value={ground.geo_data}
|
||||
/>{" "}
|
||||
</div>
|
||||
<div>
|
||||
<RadioGroup
|
||||
label="1. Projektowany/istniejący"
|
||||
size={16}
|
||||
value={objValue1}
|
||||
options={objOptions1}
|
||||
onChange={(event) => {
|
||||
setObjValue1(event.target.value);
|
||||
setGround((current) => ({
|
||||
...current,
|
||||
objValue1: event.target.value,
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
<TextInputField
|
||||
label="2. Nazwa uziemianego obiektu"
|
||||
// description=""
|
||||
placeholder={"ZK2a-1P lub słup nr 54"}
|
||||
width={440}
|
||||
onChange={(e) =>
|
||||
setGround((current) => ({
|
||||
...current,
|
||||
objName: e.target.value,
|
||||
}))
|
||||
}
|
||||
value={ground.objName}
|
||||
/>
|
||||
<Button
|
||||
onClick={() => {
|
||||
const res = getGrounding(
|
||||
parseInt(neededValue),
|
||||
parseFloat(resHValue),
|
||||
parseFloat(resVValue),
|
||||
ground.date
|
||||
);
|
||||
setGround((current) => ({ ...current, ...res }));
|
||||
}}
|
||||
appearance="primary"
|
||||
// className="p-2 bg-slate-200 rounded-md"
|
||||
>
|
||||
Oblicz Uziemienie
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
onClick={() => {
|
||||
const docx = generateDocument(ground);
|
||||
}}
|
||||
appearance="primary"
|
||||
// className="p-2 bg-slate-200 rounded-md"
|
||||
>
|
||||
Generuj Opis
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
onClick={generateDxf}
|
||||
appearance="primary"
|
||||
// className="p-2 bg-slate-200 rounded-md"
|
||||
>
|
||||
Generuj Rysunek
|
||||
</Button>
|
||||
<h2>
|
||||
Uziemienie poziome: {ground.result_h} Ω ({ground.wszrg_h})
|
||||
</h2>
|
||||
<h2>
|
||||
Uziemienie pionowe: {ground.result_v} Ω ({ground.wszrg_v})
|
||||
</h2>
|
||||
<h2>Uziemienie: {ground.result} Ω</h2>
|
||||
<h2>Szpile: {ground.rod_num} szt</h2>
|
||||
<h2>Bednarka: {ground.hor_len} m</h2>
|
||||
<Layout title="Wastpol - Kalkulator uziemień">
|
||||
<div className="p-6 max-w-7xl mx-auto">
|
||||
{/* Page Header */}
|
||||
<div className="mb-8">
|
||||
<div className="flex items-center space-x-3 mb-4">
|
||||
<div className="p-3 bg-yellow-100 rounded-lg">
|
||||
<LightningBoltIcon className="w-8 h-8 text-yellow-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold text-gray-900">Kalkulator uziemień</h1>
|
||||
<p className="text-gray-600">Oblicz parametry układu uziomowego i wygeneruj dokumentację</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
||||
{/* Input Data Section */}
|
||||
<div className="lg:col-span-2 space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center space-x-2">
|
||||
<ClipboardListIcon className="w-5 h-5 text-blue-600" />
|
||||
<span>Dane pomiarowe</span>
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Wprowadź podstawowe dane pomiarowe i parametry projektu
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
Data wykonania pomiaru
|
||||
</label>
|
||||
<DatePicker
|
||||
locale="pl"
|
||||
selected={calDate}
|
||||
onChange={(date) => {
|
||||
setCalDate(date);
|
||||
const day = date.getDate().toString().padStart(2, "0");
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
||||
const year = date.getFullYear();
|
||||
const formattedDate = `${day}.${month}.${year}`;
|
||||
setGround((current) => ({ ...current, date: formattedDate }));
|
||||
}}
|
||||
placeholderText="Wybierz datę"
|
||||
dateFormat="dd.MM.yyyy"
|
||||
className="block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
Wymagane uziemienie
|
||||
</label>
|
||||
<div className="space-y-2">
|
||||
{options.map((option) => (
|
||||
<label key={option.value} className="flex items-center">
|
||||
<input
|
||||
type="radio"
|
||||
value={option.value}
|
||||
checked={neededValue === option.value}
|
||||
onChange={(e) => setNeededValue(e.target.value)}
|
||||
className="mr-2"
|
||||
/>
|
||||
<span>{option.label}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Input
|
||||
label="Rezystywność gruntu pozioma (Ωm)"
|
||||
placeholder="86"
|
||||
value={resHValue}
|
||||
onChange={(e) => {
|
||||
setResHValue(e.target.value);
|
||||
const val = parseInt(e.target.value);
|
||||
const randomV = ground.wanted == 30 ?
|
||||
getRandomInt(val - 10, val - 4) :
|
||||
getRandomInt(val - 20, val - 10);
|
||||
setResVValue(randomV.toString());
|
||||
}}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Numer protokołu pomiarowego"
|
||||
placeholder="435"
|
||||
value={ground.no}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, no: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<Input
|
||||
label="Tytuł projektu"
|
||||
placeholder="Budowa przyłącza kablowego nN"
|
||||
value={ground.pr_title}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, pr_title: e.target.value }))}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Obiekt"
|
||||
placeholder="Przyłącz kablowy nN"
|
||||
value={ground.object}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, object: e.target.value }))}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Miejscowość"
|
||||
placeholder="Paszyn"
|
||||
value={ground.in_city}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, in_city: e.target.value }))}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Gmina/Obręb"
|
||||
placeholder="gm. Chełmiec"
|
||||
value={ground.commune}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, commune: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<Input
|
||||
label="Wszystkie działki"
|
||||
placeholder="423, 424, 425"
|
||||
value={ground.all_parcels}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, all_parcels: e.target.value }))}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Działka przyłączana"
|
||||
placeholder="423"
|
||||
value={ground.target_parcel}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, target_parcel: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Input
|
||||
label="Współrzędne układu uziomowego"
|
||||
placeholder="49°42'54"N 20°38'0"E"
|
||||
value={ground.geo_data}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, geo_data: e.target.value }))}
|
||||
/>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
Typ obiektu
|
||||
</label>
|
||||
<div className="space-y-2">
|
||||
{objOptions1.map((option) => (
|
||||
<label key={option.value} className="flex items-center">
|
||||
<input
|
||||
type="radio"
|
||||
value={option.value}
|
||||
checked={objValue1 === option.value}
|
||||
onChange={(e) => {
|
||||
setObjValue1(e.target.value);
|
||||
setGround(curr => ({ ...curr, objValue1: e.target.value }));
|
||||
}}
|
||||
className="mr-2"
|
||||
/>
|
||||
<span>{option.label}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Input
|
||||
label="Nazwa uziemianego obiektu"
|
||||
placeholder="ZK2a-1P lub słup nr 54"
|
||||
value={ground.objName}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, objName: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Results and Actions Section */}
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center space-x-2">
|
||||
<CalculatorIcon className="w-5 h-5 text-green-600" />
|
||||
<span>Obliczenia</span>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<Button
|
||||
onClick={calculateGrounding}
|
||||
disabled={!ground.date || !resHValue || !resVValue || isCalculating}
|
||||
loading={isCalculating}
|
||||
className="w-full"
|
||||
>
|
||||
<CalculatorIcon className="w-5 h-5 mr-2" />
|
||||
{isCalculating ? 'Obliczanie...' : 'Oblicz uziemienie'}
|
||||
</Button>
|
||||
|
||||
{ground.result > 0 && (
|
||||
<div className="space-y-3">
|
||||
<Alert variant="success">
|
||||
<div className="space-y-2">
|
||||
<div className="flex justify-between">
|
||||
<span>Uziemienie poziome:</span>
|
||||
<Badge variant="info">{ground.result_h} Ω</Badge>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span>Uziemienie pionowe:</span>
|
||||
<Badge variant="info">{ground.result_v} Ω</Badge>
|
||||
</div>
|
||||
<div className="flex justify-between font-semibold">
|
||||
<span>Uziemienie całkowite:</span>
|
||||
<Badge variant="success">{ground.result} Ω</Badge>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span>Liczba szpil:</span>
|
||||
<Badge>{ground.rod_num} szt</Badge>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span>Długość bednarki:</span>
|
||||
<Badge>{ground.hor_len} m</Badge>
|
||||
</div>
|
||||
</div>
|
||||
</Alert>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center space-x-2">
|
||||
<DocumentDownloadIcon className="w-5 h-5 text-purple-600" />
|
||||
<span>Generuj dokumentację</span>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<Button
|
||||
onClick={generateDocument}
|
||||
disabled={ground.result <= 0 || isGeneratingDoc}
|
||||
loading={isGeneratingDoc}
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
>
|
||||
{isGeneratingDoc ? 'Generowanie...' : 'Generuj opis (DOCX)'}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
onClick={generateDxf}
|
||||
disabled={ground.result <= 0 || isGeneratingDxf}
|
||||
loading={isGeneratingDxf}
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
>
|
||||
{isGeneratingDxf ? 'Generowanie...' : 'Generuj rysunek (DXF)'}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Instructions */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Instrukcje</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3 text-sm">
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-6 h-6 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-xs font-semibold text-blue-600">1</span>
|
||||
</div>
|
||||
<p className="text-gray-600">Wprowadź dane pomiarowe i parametry projektu</p>
|
||||
</div>
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-6 h-6 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-xs font-semibold text-blue-600">2</span>
|
||||
</div>
|
||||
<p className="text-gray-600">Kliknij "Oblicz uziemienie" aby wykonać kalkulacje</p>
|
||||
</div>
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-6 h-6 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-xs font-semibold text-blue-600">3</span>
|
||||
</div>
|
||||
<p className="text-gray-600">Wygeneruj dokumentację - opis i rysunek techniczny</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid place-items-center h-screen">
|
||||
<Head>
|
||||
<title>Wastpol</title>
|
||||
</Head>
|
||||
<div className="flex flex-col justify-center">
|
||||
<h2 className="p-2">Nie zalogowano</h2>
|
||||
<br></br>
|
||||
<Button
|
||||
onClick={() => signIn()}
|
||||
appearance="primary"
|
||||
// className="p-2 bg-slate-200 rounded-md"
|
||||
>
|
||||
Zaloguj
|
||||
</Button>
|
||||
</div>
|
||||
<div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
<CardHeader className="text-center">
|
||||
<div className="mx-auto w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mb-4">
|
||||
<img src="/logo.png" alt="Wastpol" className="w-10 h-10" />
|
||||
</div>
|
||||
<CardTitle className="text-2xl">Zaloguj się</CardTitle>
|
||||
<p className="text-gray-600 mt-2">Uzyskaj dostęp do kalkulatora uziemień</p>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Button onClick={() => signIn()} className="w-full" size="lg">
|
||||
Zaloguj się
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
545
pages/uziomy_new.js
Normal file
545
pages/uziomy_new.js
Normal file
@@ -0,0 +1,545 @@
|
||||
import { useState } from "react";
|
||||
import { useSession, signIn } from "next-auth/react";
|
||||
import Layout from "../components/ui/Layout";
|
||||
import { Card, CardHeader, CardContent, CardTitle, CardDescription, Button, Input, Badge, Alert } from "../components/ui/components";
|
||||
import { BoltIcon as LightningBoltIcon, CalculatorIcon, DocumentArrowDownIcon as DocumentDownloadIcon, ClipboardDocumentListIcon as ClipboardListIcon } from '@heroicons/react/24/outline';
|
||||
import DatePicker from "react-datepicker";
|
||||
import { registerLocale } from "react-datepicker";
|
||||
import "react-datepicker/dist/react-datepicker.css";
|
||||
import pl from "date-fns/locale/pl";
|
||||
import PizZip from "pizzip";
|
||||
import Docxtemplater from "docxtemplater";
|
||||
registerLocale("pl", pl);
|
||||
|
||||
export default function Uziomy() {
|
||||
const { data: session } = useSession();
|
||||
const [currentStep, setCurrentStep] = useState(1);
|
||||
const [isCalculating, setIsCalculating] = useState(false);
|
||||
const [isGeneratingDoc, setIsGeneratingDoc] = useState(false);
|
||||
const [isGeneratingDxf, setIsGeneratingDxf] = useState(false);
|
||||
const [calDate, setCalDate] = useState(null);
|
||||
|
||||
const [ground, setGround] = useState({
|
||||
wet_coef: 0,
|
||||
resistivity: 0,
|
||||
resistance: 0,
|
||||
measure_dist: 0,
|
||||
rod_len: 0,
|
||||
rod_num: 0,
|
||||
rod_coef: 0,
|
||||
hor_len: 0,
|
||||
result_v: 0,
|
||||
result_h: 0,
|
||||
result: 0,
|
||||
wszrg_h: 0,
|
||||
wszrg_v: 0,
|
||||
wanted: 0,
|
||||
date: undefined,
|
||||
no: 0,
|
||||
pr_title: "Budowa przyłącza kablowego nN",
|
||||
in_city: undefined,
|
||||
commune: undefined,
|
||||
all_parcels: undefined,
|
||||
target_parcel: undefined,
|
||||
geo_data: undefined,
|
||||
object: "Przyłącz kablowy nN",
|
||||
objValue1: "proj.",
|
||||
objName: undefined,
|
||||
});
|
||||
|
||||
const [options] = useState([
|
||||
{ label: "5 Ω", value: "5" },
|
||||
{ label: "10 Ω", value: "10" },
|
||||
{ label: "15 Ω", value: "15" },
|
||||
{ label: "30 Ω", value: "30" },
|
||||
]);
|
||||
const [neededValue, setNeededValue] = useState("5");
|
||||
const [resHValue, setResHValue] = useState("88");
|
||||
const [resVValue, setResVValue] = useState("89");
|
||||
|
||||
const [objOptions1] = useState([
|
||||
{ label: "proj.", value: "proj." },
|
||||
{ label: "istn.", value: "istn." },
|
||||
]);
|
||||
const [objValue1, setObjValue1] = useState("proj.");
|
||||
|
||||
function getRandomInt(min, max) {
|
||||
min = Math.ceil(min);
|
||||
max = Math.floor(max);
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
function parseDate(dateString) {
|
||||
const parts = dateString.split(".");
|
||||
const day = parseInt(parts[0], 10);
|
||||
const month = parseInt(parts[1], 10) - 1;
|
||||
const year = parseInt(parts[2], 10);
|
||||
return new Date(year, month, day);
|
||||
}
|
||||
|
||||
function getGrounding(wanted, wszrg_h, wszrg_v, date) {
|
||||
const dateObject = parseDate(date);
|
||||
const month = dateObject.getMonth() + 1;
|
||||
|
||||
const wet_coef = month >= 6 && month <= 9 ? 1.2 : 1.6;
|
||||
const rod_len = wanted === 30 ? 2 : 3;
|
||||
|
||||
const resistivity_h = wszrg_h / wet_coef;
|
||||
const measure_dist_h = 1;
|
||||
const resistance_h = resistivity_h / (2 * Math.PI * measure_dist_h);
|
||||
|
||||
const resistivity_v = wszrg_v / wet_coef;
|
||||
const measure_dist_v = 1 + rod_len;
|
||||
const resistance_v = resistivity_v / (2 * Math.PI * measure_dist_v);
|
||||
|
||||
const result_v = (wszrg_v / (2 * Math.PI * rod_len)) * (Math.log((8 * rod_len) / 0.016) - 1);
|
||||
|
||||
let rod_num = 2;
|
||||
let hor_len = 1 + (rod_num - 1) * rod_len * 2;
|
||||
let result_h = (wszrg_h / (2 * Math.PI * hor_len)) * Math.log((hor_len * hor_len) / (1 * 0.0191));
|
||||
|
||||
let rod_coef = Math.pow(rod_num, 4) * 0.00002 - Math.pow(rod_num, 3) * 0.0009 +
|
||||
Math.pow(rod_num, 2) * 0.0137 - rod_num * 0.0981 + 1.0468;
|
||||
|
||||
let result = (result_v * result_h) / (result_v * rod_coef + rod_num * result_h * rod_coef);
|
||||
|
||||
while (result > wanted) {
|
||||
rod_num += 1;
|
||||
hor_len = 1 + (rod_num - 1) * rod_len * 2;
|
||||
result_h = (wszrg_h / (2 * Math.PI * hor_len)) * Math.log((hor_len * hor_len) / (1 * 0.0191));
|
||||
rod_coef = Math.pow(rod_num, 4) * 0.00002 - Math.pow(rod_num, 3) * 0.0009 +
|
||||
Math.pow(rod_num, 2) * 0.0137 - rod_num * 0.0981 + 1.0468;
|
||||
result = (result_v * result_h) / (result_v * rod_coef + rod_num * result_h * rod_coef);
|
||||
}
|
||||
|
||||
return {
|
||||
wet_coef: wet_coef,
|
||||
resistivity_h: resistivity_h.toFixed(2),
|
||||
resistance_h: resistance_h.toFixed(2),
|
||||
measure_dist_h: measure_dist_h,
|
||||
resistivity_v: resistivity_v.toFixed(2),
|
||||
resistance_v: resistance_v.toFixed(2),
|
||||
measure_dist_v: measure_dist_v,
|
||||
rod_len: rod_len,
|
||||
rod_num: rod_num,
|
||||
rod_coef: rod_coef.toFixed(2),
|
||||
hor_len: hor_len,
|
||||
result_v: result_v.toFixed(2),
|
||||
result_h: result_h.toFixed(2),
|
||||
result: result.toFixed(2),
|
||||
wszrg_h: wszrg_h,
|
||||
wszrg_v: wszrg_v,
|
||||
wanted: neededValue,
|
||||
};
|
||||
}
|
||||
|
||||
const calculateGrounding = () => {
|
||||
setIsCalculating(true);
|
||||
try {
|
||||
const res = getGrounding(
|
||||
parseInt(neededValue),
|
||||
parseFloat(resHValue),
|
||||
parseFloat(resVValue),
|
||||
ground.date
|
||||
);
|
||||
setGround((current) => ({ ...current, ...res }));
|
||||
} catch (error) {
|
||||
alert("Błąd podczas obliczeń: " + error.message);
|
||||
}
|
||||
setIsCalculating(false);
|
||||
};
|
||||
|
||||
const generateDocument = async () => {
|
||||
setIsGeneratingDoc(true);
|
||||
const data = {
|
||||
...ground,
|
||||
resisted_object: ground.objValue1 + " " + ground.objName,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/generateDocx", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error("Response was not ok.");
|
||||
|
||||
const blob = await response.blob();
|
||||
const downloadUrl = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = downloadUrl;
|
||||
a.download = "opis_uziemienia.docx";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
alert("Błąd podczas generowania dokumentu");
|
||||
}
|
||||
setIsGeneratingDoc(false);
|
||||
};
|
||||
|
||||
const generateDxf = async () => {
|
||||
setIsGeneratingDxf(true);
|
||||
const dateParts = ground.date.split(".");
|
||||
const month = dateParts[1];
|
||||
const year = parseInt(dateParts[2], 10);
|
||||
const formattedDate = month.padStart(2, "0") + "." + year;
|
||||
|
||||
const inputData = {
|
||||
args: [
|
||||
ground.objValue1 + ground.objName,
|
||||
ground.pr_title,
|
||||
ground.object,
|
||||
ground.in_city + ", " + ground.commune + ", dz. nr " + ground.all_parcels,
|
||||
formattedDate,
|
||||
ground.hor_len,
|
||||
ground.rod_len,
|
||||
],
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/generateDxf", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(inputData),
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error("Response was not ok.");
|
||||
|
||||
const blob = await response.blob();
|
||||
const downloadUrl = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = downloadUrl;
|
||||
a.download = "uziom.dxf";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
alert("Błąd podczas generowania rysunku");
|
||||
}
|
||||
setIsGeneratingDxf(false);
|
||||
};
|
||||
|
||||
if (session) {
|
||||
return (
|
||||
<Layout title="Wastpol - Kalkulator uziemień">
|
||||
<div className="p-6 max-w-7xl mx-auto">
|
||||
{/* Page Header */}
|
||||
<div className="mb-8">
|
||||
<div className="flex items-center space-x-3 mb-4">
|
||||
<div className="p-3 bg-yellow-100 rounded-lg">
|
||||
<LightningBoltIcon className="w-8 h-8 text-yellow-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold text-gray-900">Kalkulator uziemień</h1>
|
||||
<p className="text-gray-600">Oblicz parametry układu uziomowego i wygeneruj dokumentację</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
||||
{/* Input Data Section */}
|
||||
<div className="lg:col-span-2 space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center space-x-2">
|
||||
<ClipboardListIcon className="w-5 h-5 text-blue-600" />
|
||||
<span>Dane pomiarowe</span>
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Wprowadź podstawowe dane pomiarowe i parametry projektu
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
Data wykonania pomiaru
|
||||
</label>
|
||||
<DatePicker
|
||||
locale="pl"
|
||||
selected={calDate}
|
||||
onChange={(date) => {
|
||||
setCalDate(date);
|
||||
const day = date.getDate().toString().padStart(2, "0");
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
||||
const year = date.getFullYear();
|
||||
const formattedDate = `${day}.${month}.${year}`;
|
||||
setGround((current) => ({ ...current, date: formattedDate }));
|
||||
}}
|
||||
placeholderText="Wybierz datę"
|
||||
dateFormat="dd.MM.yyyy"
|
||||
className="block w-full rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
Wymagane uziemienie
|
||||
</label>
|
||||
<div className="space-y-2">
|
||||
{options.map((option) => (
|
||||
<label key={option.value} className="flex items-center">
|
||||
<input
|
||||
type="radio"
|
||||
value={option.value}
|
||||
checked={neededValue === option.value}
|
||||
onChange={(e) => setNeededValue(e.target.value)}
|
||||
className="mr-2"
|
||||
/>
|
||||
<span>{option.label}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Input
|
||||
label="Rezystywność gruntu pozioma (Ωm)"
|
||||
placeholder="86"
|
||||
value={resHValue}
|
||||
onChange={(e) => {
|
||||
setResHValue(e.target.value);
|
||||
const val = parseInt(e.target.value);
|
||||
const randomV = ground.wanted == 30 ?
|
||||
getRandomInt(val - 10, val - 4) :
|
||||
getRandomInt(val - 20, val - 10);
|
||||
setResVValue(randomV.toString());
|
||||
}}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Numer protokołu pomiarowego"
|
||||
placeholder="435"
|
||||
value={ground.no}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, no: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<Input
|
||||
label="Tytuł projektu"
|
||||
placeholder="Budowa przyłącza kablowego nN"
|
||||
value={ground.pr_title}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, pr_title: e.target.value }))}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Obiekt"
|
||||
placeholder="Przyłącz kablowy nN"
|
||||
value={ground.object}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, object: e.target.value }))}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Miejscowość"
|
||||
placeholder="Paszyn"
|
||||
value={ground.in_city}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, in_city: e.target.value }))}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Gmina/Obręb"
|
||||
placeholder="gm. Chełmiec"
|
||||
value={ground.commune}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, commune: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<Input
|
||||
label="Wszystkie działki"
|
||||
placeholder="423, 424, 425"
|
||||
value={ground.all_parcels}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, all_parcels: e.target.value }))}
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Działka przyłączana"
|
||||
placeholder="423"
|
||||
value={ground.target_parcel}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, target_parcel: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Input
|
||||
label="Współrzędne układu uziomowego"
|
||||
placeholder="49°42'54"N 20°38'0"E"
|
||||
value={ground.geo_data}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, geo_data: e.target.value }))}
|
||||
/>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
Typ obiektu
|
||||
</label>
|
||||
<div className="space-y-2">
|
||||
{objOptions1.map((option) => (
|
||||
<label key={option.value} className="flex items-center">
|
||||
<input
|
||||
type="radio"
|
||||
value={option.value}
|
||||
checked={objValue1 === option.value}
|
||||
onChange={(e) => {
|
||||
setObjValue1(e.target.value);
|
||||
setGround(curr => ({ ...curr, objValue1: e.target.value }));
|
||||
}}
|
||||
className="mr-2"
|
||||
/>
|
||||
<span>{option.label}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Input
|
||||
label="Nazwa uziemianego obiektu"
|
||||
placeholder="ZK2a-1P lub słup nr 54"
|
||||
value={ground.objName}
|
||||
onChange={(e) => setGround(curr => ({ ...curr, objName: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Results and Actions Section */}
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center space-x-2">
|
||||
<CalculatorIcon className="w-5 h-5 text-green-600" />
|
||||
<span>Obliczenia</span>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<Button
|
||||
onClick={calculateGrounding}
|
||||
disabled={!ground.date || !resHValue || !resVValue || isCalculating}
|
||||
loading={isCalculating}
|
||||
className="w-full"
|
||||
>
|
||||
<CalculatorIcon className="w-5 h-5 mr-2" />
|
||||
{isCalculating ? 'Obliczanie...' : 'Oblicz uziemienie'}
|
||||
</Button>
|
||||
|
||||
{ground.result > 0 && (
|
||||
<div className="space-y-3">
|
||||
<Alert variant="success">
|
||||
<div className="space-y-2">
|
||||
<div className="flex justify-between">
|
||||
<span>Uziemienie poziome:</span>
|
||||
<Badge variant="info">{ground.result_h} Ω</Badge>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span>Uziemienie pionowe:</span>
|
||||
<Badge variant="info">{ground.result_v} Ω</Badge>
|
||||
</div>
|
||||
<div className="flex justify-between font-semibold">
|
||||
<span>Uziemienie całkowite:</span>
|
||||
<Badge variant="success">{ground.result} Ω</Badge>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span>Liczba szpil:</span>
|
||||
<Badge>{ground.rod_num} szt</Badge>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span>Długość bednarki:</span>
|
||||
<Badge>{ground.hor_len} m</Badge>
|
||||
</div>
|
||||
</div>
|
||||
</Alert>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center space-x-2">
|
||||
<DocumentDownloadIcon className="w-5 h-5 text-purple-600" />
|
||||
<span>Generuj dokumentację</span>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<Button
|
||||
onClick={generateDocument}
|
||||
disabled={ground.result <= 0 || isGeneratingDoc}
|
||||
loading={isGeneratingDoc}
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
>
|
||||
{isGeneratingDoc ? 'Generowanie...' : 'Generuj opis (DOCX)'}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
onClick={generateDxf}
|
||||
disabled={ground.result <= 0 || isGeneratingDxf}
|
||||
loading={isGeneratingDxf}
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
>
|
||||
{isGeneratingDxf ? 'Generowanie...' : 'Generuj rysunek (DXF)'}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Instructions */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Instrukcje</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3 text-sm">
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-6 h-6 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-xs font-semibold text-blue-600">1</span>
|
||||
</div>
|
||||
<p className="text-gray-600">Wprowadź dane pomiarowe i parametry projektu</p>
|
||||
</div>
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-6 h-6 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-xs font-semibold text-blue-600">2</span>
|
||||
</div>
|
||||
<p className="text-gray-600">Kliknij "Oblicz uziemienie" aby wykonać kalkulacje</p>
|
||||
</div>
|
||||
<div className="flex items-start space-x-3">
|
||||
<div className="flex-shrink-0 w-6 h-6 bg-blue-100 rounded-full flex items-center justify-center">
|
||||
<span className="text-xs font-semibold text-blue-600">3</span>
|
||||
</div>
|
||||
<p className="text-gray-600">Wygeneruj dokumentację - opis i rysunek techniczny</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
<CardHeader className="text-center">
|
||||
<div className="mx-auto w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mb-4">
|
||||
<img src="/logo.png" alt="Wastpol" className="w-10 h-10" />
|
||||
</div>
|
||||
<CardTitle className="text-2xl">Zaloguj się</CardTitle>
|
||||
<p className="text-gray-600 mt-2">Uzyskaj dostęp do kalkulatora uziemień</p>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Button onClick={() => signIn()} className="w-full" size="lg">
|
||||
Zaloguj się
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user