Compare commits
No files matched your search
@@ -0,0 +1,12 @@
|
|||||||
|
# Pamhyr .editorconfig
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*.py]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
tab_width = 8
|
||||||
|
end_of_line = lf
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
### CUSTOM ###
|
### CUSTOM ###
|
||||||
|
|
||||||
*.exe
|
*.exe
|
||||||
|
*.msi
|
||||||
*.tar.xz
|
*.tar.xz
|
||||||
*.zip
|
*.zip
|
||||||
*.spec
|
*.spec
|
||||||
@@ -9,15 +10,33 @@
|
|||||||
|
|
||||||
tmp
|
tmp
|
||||||
|
|
||||||
|
*.tar
|
||||||
*.tar.*
|
*.tar.*
|
||||||
|
*.tgz
|
||||||
*.zip
|
*.zip
|
||||||
|
|
||||||
|
*.html
|
||||||
|
*.pdf
|
||||||
|
*.odt
|
||||||
|
|
||||||
|
doc/dev/images/auto_*
|
||||||
|
doc/dev/documentation.*
|
||||||
|
!doc/dev/*.org
|
||||||
|
|
||||||
|
doc/dev/images/auto_*
|
||||||
|
doc/users/documentation.*
|
||||||
|
!doc/users/*.org
|
||||||
|
|
||||||
|
TAGS
|
||||||
|
|
||||||
pamhyrBuild
|
pamhyrBuild
|
||||||
wine-pamhyr-build*
|
wine-pamhyr-build*
|
||||||
|
|
||||||
_PAMHYR_
|
_PAMHYR_
|
||||||
__old__
|
__old__
|
||||||
|
|
||||||
|
*-venv
|
||||||
|
|
||||||
### END CUSTOM ###
|
### END CUSTOM ###
|
||||||
|
|
||||||
# Created by https://www.toptal.com/developers/gitignore/api/python
|
# Created by https://www.toptal.com/developers/gitignore/api/python
|
||||||
@@ -309,3 +328,318 @@ compile_commands.json
|
|||||||
*_qmlcache.qrc
|
*_qmlcache.qrc
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/qt
|
# End of https://www.toptal.com/developers/gitignore/api/qt
|
||||||
|
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/latex
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=latex
|
||||||
|
|
||||||
|
### LaTeX ###
|
||||||
|
## Core latex/pdflatex auxiliary files:
|
||||||
|
*.aux
|
||||||
|
*.lof
|
||||||
|
*.log
|
||||||
|
*.lot
|
||||||
|
*.fls
|
||||||
|
*.out
|
||||||
|
*.toc
|
||||||
|
*.fmt
|
||||||
|
*.fot
|
||||||
|
*.cb
|
||||||
|
*.cb2
|
||||||
|
.*.lb
|
||||||
|
|
||||||
|
## Intermediate documents:
|
||||||
|
*.dvi
|
||||||
|
*.xdv
|
||||||
|
*-converted-to.*
|
||||||
|
# these rules might exclude image files for figures etc.
|
||||||
|
# *.ps
|
||||||
|
# *.eps
|
||||||
|
# *.pdf
|
||||||
|
|
||||||
|
## Generated if empty string is given at "Please type another file name for output:"
|
||||||
|
.pdf
|
||||||
|
|
||||||
|
## Bibliography auxiliary files (bibtex/biblatex/biber):
|
||||||
|
*.bbl
|
||||||
|
*.bcf
|
||||||
|
*.blg
|
||||||
|
*-blx.aux
|
||||||
|
*-blx.bib
|
||||||
|
*.run.xml
|
||||||
|
|
||||||
|
## Build tool auxiliary files:
|
||||||
|
*.fdb_latexmk
|
||||||
|
*.synctex
|
||||||
|
*.synctex(busy)
|
||||||
|
*.synctex.gz
|
||||||
|
*.synctex.gz(busy)
|
||||||
|
*.pdfsync
|
||||||
|
|
||||||
|
## Build tool directories for auxiliary files
|
||||||
|
# latexrun
|
||||||
|
latex.out/
|
||||||
|
|
||||||
|
## Auxiliary and intermediate files from other packages:
|
||||||
|
# algorithms
|
||||||
|
*.alg
|
||||||
|
*.loa
|
||||||
|
|
||||||
|
# achemso
|
||||||
|
acs-*.bib
|
||||||
|
|
||||||
|
# amsthm
|
||||||
|
*.thm
|
||||||
|
|
||||||
|
# beamer
|
||||||
|
*.nav
|
||||||
|
*.pre
|
||||||
|
*.snm
|
||||||
|
*.vrb
|
||||||
|
|
||||||
|
# changes
|
||||||
|
*.soc
|
||||||
|
|
||||||
|
# comment
|
||||||
|
*.cut
|
||||||
|
|
||||||
|
# cprotect
|
||||||
|
*.cpt
|
||||||
|
|
||||||
|
# elsarticle (documentclass of Elsevier journals)
|
||||||
|
*.spl
|
||||||
|
|
||||||
|
# endnotes
|
||||||
|
*.ent
|
||||||
|
|
||||||
|
# fixme
|
||||||
|
*.lox
|
||||||
|
|
||||||
|
# feynmf/feynmp
|
||||||
|
*.mf
|
||||||
|
*.mp
|
||||||
|
*.t[1-9]
|
||||||
|
*.t[1-9][0-9]
|
||||||
|
*.tfm
|
||||||
|
|
||||||
|
#(r)(e)ledmac/(r)(e)ledpar
|
||||||
|
*.end
|
||||||
|
*.?end
|
||||||
|
*.[1-9]
|
||||||
|
*.[1-9][0-9]
|
||||||
|
*.[1-9][0-9][0-9]
|
||||||
|
*.[1-9]R
|
||||||
|
*.[1-9][0-9]R
|
||||||
|
*.[1-9][0-9][0-9]R
|
||||||
|
*.eledsec[1-9]
|
||||||
|
*.eledsec[1-9]R
|
||||||
|
*.eledsec[1-9][0-9]
|
||||||
|
*.eledsec[1-9][0-9]R
|
||||||
|
*.eledsec[1-9][0-9][0-9]
|
||||||
|
*.eledsec[1-9][0-9][0-9]R
|
||||||
|
|
||||||
|
# glossaries
|
||||||
|
*.acn
|
||||||
|
*.acr
|
||||||
|
*.glg
|
||||||
|
*.glo
|
||||||
|
*.gls
|
||||||
|
*.glsdefs
|
||||||
|
*.lzo
|
||||||
|
*.lzs
|
||||||
|
*.slg
|
||||||
|
*.slo
|
||||||
|
*.sls
|
||||||
|
|
||||||
|
# uncomment this for glossaries-extra (will ignore makeindex's style files!)
|
||||||
|
# *.ist
|
||||||
|
|
||||||
|
# gnuplot
|
||||||
|
*.gnuplot
|
||||||
|
*.table
|
||||||
|
|
||||||
|
# gnuplottex
|
||||||
|
*-gnuplottex-*
|
||||||
|
|
||||||
|
# gregoriotex
|
||||||
|
*.gaux
|
||||||
|
*.glog
|
||||||
|
*.gtex
|
||||||
|
|
||||||
|
# htlatex
|
||||||
|
*.4ct
|
||||||
|
*.4tc
|
||||||
|
*.idv
|
||||||
|
*.lg
|
||||||
|
*.trc
|
||||||
|
*.xref
|
||||||
|
|
||||||
|
# hyperref
|
||||||
|
*.brf
|
||||||
|
|
||||||
|
# knitr
|
||||||
|
*-concordance.tex
|
||||||
|
# TODO Uncomment the next line if you use knitr and want to ignore its generated tikz files
|
||||||
|
# *.tikz
|
||||||
|
*-tikzDictionary
|
||||||
|
|
||||||
|
# listings
|
||||||
|
*.lol
|
||||||
|
|
||||||
|
# luatexja-ruby
|
||||||
|
*.ltjruby
|
||||||
|
|
||||||
|
# makeidx
|
||||||
|
*.idx
|
||||||
|
*.ilg
|
||||||
|
*.ind
|
||||||
|
|
||||||
|
# minitoc
|
||||||
|
*.maf
|
||||||
|
*.mlf
|
||||||
|
*.mlt
|
||||||
|
*.mtc[0-9]*
|
||||||
|
*.slf[0-9]*
|
||||||
|
*.slt[0-9]*
|
||||||
|
*.stc[0-9]*
|
||||||
|
|
||||||
|
# minted
|
||||||
|
_minted*
|
||||||
|
*.pyg
|
||||||
|
|
||||||
|
# morewrites
|
||||||
|
*.mw
|
||||||
|
|
||||||
|
# newpax
|
||||||
|
*.newpax
|
||||||
|
|
||||||
|
# nomencl
|
||||||
|
*.nlg
|
||||||
|
*.nlo
|
||||||
|
*.nls
|
||||||
|
|
||||||
|
# pax
|
||||||
|
*.pax
|
||||||
|
|
||||||
|
# pdfpcnotes
|
||||||
|
*.pdfpc
|
||||||
|
|
||||||
|
# sagetex
|
||||||
|
*.sagetex.sage
|
||||||
|
*.sagetex.py
|
||||||
|
*.sagetex.scmd
|
||||||
|
|
||||||
|
# scrwfile
|
||||||
|
*.wrt
|
||||||
|
|
||||||
|
# svg
|
||||||
|
svg-inkscape/
|
||||||
|
|
||||||
|
# sympy
|
||||||
|
*.sout
|
||||||
|
*.sympy
|
||||||
|
sympy-plots-for-*.tex/
|
||||||
|
|
||||||
|
# pdfcomment
|
||||||
|
*.upa
|
||||||
|
*.upb
|
||||||
|
|
||||||
|
# pythontex
|
||||||
|
*.pytxcode
|
||||||
|
pythontex-files-*/
|
||||||
|
|
||||||
|
# tcolorbox
|
||||||
|
*.listing
|
||||||
|
|
||||||
|
# thmtools
|
||||||
|
*.loe
|
||||||
|
|
||||||
|
# TikZ & PGF
|
||||||
|
*.dpth
|
||||||
|
*.md5
|
||||||
|
*.auxlock
|
||||||
|
|
||||||
|
# titletoc
|
||||||
|
*.ptc
|
||||||
|
|
||||||
|
# todonotes
|
||||||
|
*.tdo
|
||||||
|
|
||||||
|
# vhistory
|
||||||
|
*.hst
|
||||||
|
*.ver
|
||||||
|
|
||||||
|
# easy-todo
|
||||||
|
*.lod
|
||||||
|
|
||||||
|
# xcolor
|
||||||
|
*.xcp
|
||||||
|
|
||||||
|
# xmpincl
|
||||||
|
*.xmpi
|
||||||
|
|
||||||
|
# xindy
|
||||||
|
*.xdy
|
||||||
|
|
||||||
|
# xypic precompiled matrices and outlines
|
||||||
|
*.xyc
|
||||||
|
*.xyd
|
||||||
|
|
||||||
|
# endfloat
|
||||||
|
*.ttt
|
||||||
|
*.fff
|
||||||
|
|
||||||
|
# Latexian
|
||||||
|
TSWLatexianTemp*
|
||||||
|
|
||||||
|
## Editors:
|
||||||
|
# WinEdt
|
||||||
|
*.bak
|
||||||
|
*.sav
|
||||||
|
|
||||||
|
# Texpad
|
||||||
|
.texpadtmp
|
||||||
|
|
||||||
|
# LyX
|
||||||
|
*.lyx~
|
||||||
|
|
||||||
|
# Kile
|
||||||
|
*.backup
|
||||||
|
|
||||||
|
# gummi
|
||||||
|
.*.swp
|
||||||
|
|
||||||
|
# KBibTeX
|
||||||
|
*~[0-9]*
|
||||||
|
|
||||||
|
# TeXnicCenter
|
||||||
|
*.tps
|
||||||
|
|
||||||
|
# auto folder when using emacs and auctex
|
||||||
|
./auto/*
|
||||||
|
*.el
|
||||||
|
|
||||||
|
# expex forward references with \gathertags
|
||||||
|
*-tags.tex
|
||||||
|
|
||||||
|
# standalone packages
|
||||||
|
*.sta
|
||||||
|
|
||||||
|
# Makeindex log files
|
||||||
|
*.lpz
|
||||||
|
|
||||||
|
# xwatermark package
|
||||||
|
*.xwm
|
||||||
|
|
||||||
|
# REVTeX puts footnotes in the bibliography by default, unless the nofootinbib
|
||||||
|
# option is specified. Footnotes are the stored in a file with suffix Notes.bib.
|
||||||
|
# Uncomment the next line to have this generated file ignored.
|
||||||
|
#*Notes.bib
|
||||||
|
|
||||||
|
### LaTeX Patch ###
|
||||||
|
# LIPIcs / OASIcs
|
||||||
|
*.vtc
|
||||||
|
|
||||||
|
# glossaries
|
||||||
|
*.glstex
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/latex
|
||||||
@@ -15,97 +15,57 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- build
|
- downloads
|
||||||
|
- configure
|
||||||
- test
|
- test
|
||||||
|
- build
|
||||||
- package
|
- package
|
||||||
- release
|
- release
|
||||||
|
|
||||||
#########
|
#############
|
||||||
# BUILD #
|
# DOWNLOADS #
|
||||||
#########
|
#############
|
||||||
|
|
||||||
build-mage-linux:
|
dl-mage-linux:
|
||||||
stage: build
|
stage: downloads
|
||||||
tags:
|
tags:
|
||||||
- linux
|
- linux
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
||||||
script:
|
script:
|
||||||
- curl -L -o mage.tgz https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/Test6/downloads/packages/mage_linux.tgz
|
- curl -L -o mage.tgz https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/Test6/downloads/packages/mage_linux.tgz
|
||||||
- mkdir -p mage
|
- mkdir -p mage-linux
|
||||||
- cd mage
|
- cd mage-linux
|
||||||
- tar xvf ../mage.tgz
|
- tar xvf ../mage.tgz
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- mage/mage
|
- mage-linux/mage
|
||||||
- mage/mage_extraire
|
- mage-linux/mage_extraire
|
||||||
- mage/mailleurPF
|
- mage-linux/mailleurPF
|
||||||
|
|
||||||
# build-mage-linux:
|
dl-mage-windows:
|
||||||
# stage: build
|
stage: downloads
|
||||||
# tags:
|
|
||||||
# - linux
|
|
||||||
# rules:
|
|
||||||
# - if: $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
|
||||||
# variables:
|
|
||||||
# GIT_SUBMODULE_STRATEGY: recursive
|
|
||||||
# GIT_SUBMODULE_DEPTH: 20
|
|
||||||
# script:
|
|
||||||
# - cd mage/src/
|
|
||||||
# - mkdir -p build
|
|
||||||
# - cd build
|
|
||||||
# - cmake ..
|
|
||||||
# - make
|
|
||||||
# artifacts:
|
|
||||||
# paths:
|
|
||||||
# - mage/src/build/mage
|
|
||||||
# - mage/src/build/mage_extraire
|
|
||||||
# - mage/src/build/mailleurPF
|
|
||||||
|
|
||||||
build-mage-windows:
|
|
||||||
stage: build
|
|
||||||
tags:
|
tags:
|
||||||
- linux
|
- linux
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
||||||
script:
|
script:
|
||||||
- curl -L -o mage.tgz https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/Test6/downloads/packages/mage_windows.tgz
|
- curl -L -o mage.tgz https://gitlab.irstea.fr/jean-baptiste.faure/mage/-/releases/Test6/downloads/packages/mage_windows.tgz
|
||||||
- mkdir -p mage
|
- mkdir -p mage-windows
|
||||||
- cd mage
|
- cd mage-windows
|
||||||
- tar xvf ../mage.tgz
|
- tar xvf ../mage.tgz
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- mage/mage.exe
|
- mage-windows/mage.exe
|
||||||
- mage/mage_extraire.exe
|
- mage-windows/mage_extraire.exe
|
||||||
- mage/mailleurPF.exe
|
- mage-windows/mailleurPF.exe
|
||||||
|
|
||||||
# build-mage-windows:
|
#############
|
||||||
# stage: build
|
# CONFIGURE #
|
||||||
# tags:
|
#############
|
||||||
# - wine
|
|
||||||
# rules:
|
|
||||||
# - if: $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
|
||||||
# variables:
|
|
||||||
# GIT_SUBMODULE_STRATEGY: recursive
|
|
||||||
# GIT_SUBMODULE_DEPTH: 20
|
|
||||||
# script:
|
|
||||||
# - cd mage/src/
|
|
||||||
# - sed s/add_compile_definitions(win)/add_compile_definitions(windows)/ CMakeLists.txt > __tmp__
|
|
||||||
# - echo set(CMAKE_Fortran_COMPILER "C:/Program\ Files/gcc/bin/gfortran.exe") > CMakeLists.txt
|
|
||||||
# - echo set(CMAKE_MAKE_PROGRAM "C:/Program Files\ \(x86\)/GnuWin32/bin/make.exe") >> CMakeLists.txt
|
|
||||||
# - type __tmp__ >> CMakeLists.txt
|
|
||||||
# - mkdir build
|
|
||||||
# - cd build
|
|
||||||
# - cmake -G "MinGW Makefiles" ..
|
|
||||||
# - make
|
|
||||||
# artifacts:
|
|
||||||
# paths:
|
|
||||||
# - mage/src/build/mage.exe
|
|
||||||
# - mage/src/build/mage_extraire.exe
|
|
||||||
# - mage/src/build/mailleurPF.exe
|
|
||||||
|
|
||||||
build:
|
set-version:
|
||||||
stage: build
|
stage: configure
|
||||||
tags:
|
tags:
|
||||||
- linux
|
- linux
|
||||||
script:
|
script:
|
||||||
@@ -116,7 +76,7 @@ build:
|
|||||||
- VERSION
|
- VERSION
|
||||||
|
|
||||||
build-lang:
|
build-lang:
|
||||||
stage: build
|
stage: configure
|
||||||
tags:
|
tags:
|
||||||
- linux
|
- linux
|
||||||
script:
|
script:
|
||||||
@@ -130,56 +90,261 @@ build-lang:
|
|||||||
# TESTS #
|
# TESTS #
|
||||||
#########
|
#########
|
||||||
|
|
||||||
test:
|
unittest:
|
||||||
stage: test
|
stage: test
|
||||||
|
tags:
|
||||||
|
- linux
|
||||||
|
needs:
|
||||||
|
- job: set-version
|
||||||
|
artifacts: true
|
||||||
script:
|
script:
|
||||||
- echo "TODO PAMHYR tests"
|
- python3 -m venv venv
|
||||||
|
- . venv/bin/activate
|
||||||
|
- pip3 install -U pip
|
||||||
|
- pip3 install -r ./full-requirements.txt
|
||||||
|
- pip3 install -U -r ./full-requirements.txt
|
||||||
|
- cd src
|
||||||
|
- python3 -m unittest discover -t .
|
||||||
|
|
||||||
|
test-pep8:
|
||||||
|
stage: test
|
||||||
|
tags:
|
||||||
|
- linux
|
||||||
|
needs:
|
||||||
|
- job: set-version
|
||||||
|
artifacts: true
|
||||||
|
- job: unittest
|
||||||
|
script:
|
||||||
|
# Setup virtual env
|
||||||
|
- python3 -m venv venv
|
||||||
|
- . venv/bin/activate
|
||||||
|
- pip3 install -U pip
|
||||||
|
- pip3 install -r ./requirements.txt
|
||||||
|
- pip3 install -U -r ./requirements.txt
|
||||||
|
- pip3 install pycodestyle
|
||||||
|
- pycodestyle ./src
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
#########
|
||||||
|
# BUILD #
|
||||||
|
#########
|
||||||
|
|
||||||
|
build-users-doc:
|
||||||
|
stage: build
|
||||||
|
tags:
|
||||||
|
- linux
|
||||||
|
needs:
|
||||||
|
- job: set-version
|
||||||
|
artifacts: true
|
||||||
|
script:
|
||||||
|
- cd ./doc/users/
|
||||||
|
- ./build.sh
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- doc/users/documentation.pdf
|
||||||
|
- doc/users/documentation.html
|
||||||
|
- doc/users/images/
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
build-developers-doc:
|
||||||
|
stage: build
|
||||||
|
tags:
|
||||||
|
- linux
|
||||||
|
needs:
|
||||||
|
- job: set-version
|
||||||
|
artifacts: true
|
||||||
|
script:
|
||||||
|
- cd ./doc/dev/
|
||||||
|
- ./build.sh
|
||||||
|
# Create html documentation
|
||||||
|
- cd ../../src
|
||||||
|
- python3 -m venv doc-venv
|
||||||
|
- . doc-venv/bin/activate
|
||||||
|
- pip3 install -U pip
|
||||||
|
- pip3 install -r ../full-requirements.txt
|
||||||
|
- pip3 install -U -r ../full-requirements.txt
|
||||||
|
- pip3 install pdoc3
|
||||||
|
- pdoc --html .
|
||||||
|
# Create archive
|
||||||
|
- tar cf html.tar ./html
|
||||||
|
- cd ../doc/dev
|
||||||
|
- mv ../../src/html.tar ./
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- doc/dev/documentation.pdf
|
||||||
|
- doc/dev/documentation.html
|
||||||
|
- doc/dev/html.tar
|
||||||
|
- doc/dev/images/
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
build-linux:
|
||||||
|
stage: build
|
||||||
|
tags:
|
||||||
|
- linux
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
||||||
|
needs:
|
||||||
|
- job: dl-mage-linux
|
||||||
|
artifacts: true
|
||||||
|
- job: set-version
|
||||||
|
artifacts: true
|
||||||
|
- job: build-lang
|
||||||
|
artifacts: true
|
||||||
|
- job: build-developers-doc
|
||||||
|
artifacts: true
|
||||||
|
- job: build-users-doc
|
||||||
|
artifacts: true
|
||||||
|
script:
|
||||||
|
- mkdir -p linux
|
||||||
|
- cd linux
|
||||||
|
# Setup virtual env
|
||||||
|
- python3 -m venv linux-venv
|
||||||
|
- . linux-venv/bin/activate
|
||||||
|
- pip3 install -U pip
|
||||||
|
- pip3 install -r ../requirements.txt
|
||||||
|
- pip3 install -U -r ../requirements.txt
|
||||||
|
# Run Pyinstaller
|
||||||
|
- pyinstaller -y --paths linux-venv/lib/python3.8/site-packages ../src/pamhyr.py
|
||||||
|
# Create directory
|
||||||
|
- mkdir -p pamhyr
|
||||||
|
- mkdir -p pamhyr/pamhyr
|
||||||
|
- mkdir -p pamhyr/pamhyr/_internal
|
||||||
|
# Copy Pamhyr info
|
||||||
|
- cp -v ../VERSION pamhyr/pamhyr/_internal/
|
||||||
|
- cp -v ../AUTHORS pamhyr/pamhyr/_internal/
|
||||||
|
- cp -v ../LICENSE pamhyr/pamhyr/_internal/
|
||||||
|
- cp -v ../src/motd.txt pamhyr/pamhyr/_internal/
|
||||||
|
# Copy mage
|
||||||
|
- mkdir -p pamhyr/mage
|
||||||
|
- cp -v ../mage-linux/* pamhyr/mage/
|
||||||
|
# Copy Pamhyr
|
||||||
|
- cp -r dist/pamhyr pamhyr/
|
||||||
|
# Copy Pamhyr resources
|
||||||
|
- mkdir -p pamhyr/pamhyr/_internal/View
|
||||||
|
- mkdir -p pamhyr/pamhyr/_internal/View/ui
|
||||||
|
- mkdir -p pamhyr/pamhyr/_internal/View/ui/Widgets
|
||||||
|
- cp -r ../src/View/ui/*.ui pamhyr/pamhyr/_internal/View/ui/
|
||||||
|
- cp -r ../src/View/ui/ressources/ pamhyr/pamhyr/_internal/View/ui
|
||||||
|
- cp -r ../src/View/ui/Widgets/*.ui pamhyr/pamhyr/_internal/View/ui/Widgets
|
||||||
|
# Copy lang
|
||||||
|
- mkdir -p pamhyr/pamhyr/_internal/lang
|
||||||
|
- cp -r ../src/lang/*.qm pamhyr/pamhyr/_internal/lang
|
||||||
|
# Copy tests cases
|
||||||
|
- mkdir -p pamhyr/tests_cases/
|
||||||
|
- mkdir -p pamhyr/tests_cases/Saar
|
||||||
|
- cp ../tests_cases/Saar/Saar.pamhyr pamhyr/tests_cases/Saar/
|
||||||
|
# Copy documentations
|
||||||
|
- mkdir -p pamhyr/doc/
|
||||||
|
- mkdir -p pamhyr/doc/images/
|
||||||
|
- mkdir -p pamhyr/doc/html/
|
||||||
|
- cp ../doc/users/documentation.pdf pamhyr/doc/Pamhyr2-users.pdf
|
||||||
|
- cp ../doc/users/documentation.html pamhyr/doc/Pamhyr2-users.html
|
||||||
|
- cp ../doc/dev/documentation.pdf pamhyr/doc/Pamhyr2-dev.pdf
|
||||||
|
- cp ../doc/dev/documentation.html pamhyr/doc/Pamhyr2-dev.html
|
||||||
|
#- cp ../doc/users/images/* pamhyr/doc/images
|
||||||
|
- cp ../doc/dev/images/* pamhyr/doc/images
|
||||||
|
- cp ../doc/images/* pamhyr/doc/images
|
||||||
|
# Create running script
|
||||||
|
- echo "#!/bin/sh" > pamhyr/Pamhyr2
|
||||||
|
- echo "./pamhyr/pamhyr $@" >> pamhyr/Pamhyr2
|
||||||
|
- chmod u+x pamhyr/Pamhyr2
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- linux/pamhyr
|
||||||
|
|
||||||
|
build-windows:
|
||||||
|
stage: build
|
||||||
|
tags:
|
||||||
|
- wine
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
||||||
|
needs:
|
||||||
|
- job: dl-mage-windows
|
||||||
|
artifacts: true
|
||||||
|
- job: set-version
|
||||||
|
artifacts: true
|
||||||
|
- job: build-lang
|
||||||
|
artifacts: true
|
||||||
|
- job: build-developers-doc
|
||||||
|
artifacts: true
|
||||||
|
- job: build-users-doc
|
||||||
|
artifacts: true
|
||||||
|
script:
|
||||||
|
- mkdir windows
|
||||||
|
- cd windows
|
||||||
|
# Setup env
|
||||||
|
- python -m pip install -r ..\requirements.txt
|
||||||
|
- python -m pip install -U -r ..\requirements.txt
|
||||||
|
# Run Pyinstaller
|
||||||
|
- pyinstaller -y ..\src\pamhyr.py
|
||||||
|
# Create directory
|
||||||
|
- mkdir pamhyr
|
||||||
|
- dir
|
||||||
|
- copy ..\packages\make-windows-dir.bat .\make-windows-dir.bat
|
||||||
|
- .\make-windows-dir.bat
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- windows/pamhyr
|
||||||
|
|
||||||
############
|
############
|
||||||
# PACKAGES #
|
# PACKAGES #
|
||||||
############
|
############
|
||||||
|
|
||||||
linux-package:
|
linux-package-tar:
|
||||||
stage: package
|
stage: package
|
||||||
tags:
|
tags:
|
||||||
- release
|
- release
|
||||||
- linux
|
- linux
|
||||||
needs:
|
needs:
|
||||||
- job: build-lang
|
# - job: test-linux
|
||||||
artifacts: true
|
- job: build-linux
|
||||||
- job: build
|
|
||||||
artifacts: true
|
|
||||||
- job: build-mage-linux
|
|
||||||
artifacts: true
|
artifacts: true
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_TAG
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- packages/pamhyr-gnulinux-amd64.tar.xz
|
- linux/pamhyr-gnulinux.tar.xz
|
||||||
script:
|
script:
|
||||||
- cd packages
|
- cd linux
|
||||||
- ./linux.sh
|
- tar --xz -cf pamhyr-gnulinux.tar.xz ./pamhyr --checkpoint=.100
|
||||||
|
|
||||||
windows-package:
|
windows-package-zip:
|
||||||
|
stage: package
|
||||||
|
tags:
|
||||||
|
- release
|
||||||
|
- linux
|
||||||
|
needs:
|
||||||
|
# - job: test-windows
|
||||||
|
- job: build-windows
|
||||||
|
artifacts: true
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_TAG
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- windows/pamhyr-windows.zip
|
||||||
|
script:
|
||||||
|
- cd windows
|
||||||
|
- zip -r pamhyr-windows.zip pamhyr
|
||||||
|
|
||||||
|
windows-package-exe:
|
||||||
stage: package
|
stage: package
|
||||||
tags:
|
tags:
|
||||||
- release
|
- release
|
||||||
- wine
|
- wine
|
||||||
needs:
|
needs:
|
||||||
- job: build-lang
|
# - job: test-windows
|
||||||
artifacts: true
|
- job: build-windows
|
||||||
- job: build
|
|
||||||
artifacts: true
|
|
||||||
- job: build-mage-windows
|
|
||||||
artifacts: true
|
artifacts: true
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_BRANCH == 'master' || $CI_COMMIT_TAG
|
- if: $CI_COMMIT_BRANCH == 'ci-test' || $CI_COMMIT_TAG
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- packages/pamhyr-win-amd64.exe
|
- windows/pamhyr-windows.exe
|
||||||
script:
|
script:
|
||||||
- cd packages
|
- cd windows
|
||||||
- ./windows.bat
|
- copy ..\packages\make-windows-exe.bat make-windows-exe.bat
|
||||||
|
- copy ..\packages\pamhyr.nsi pamhyr.nsi
|
||||||
|
- .\make-windows-exe.bat
|
||||||
|
|
||||||
###########
|
###########
|
||||||
# RELEASE #
|
# RELEASE #
|
||||||
@@ -191,16 +356,25 @@ tag-release:
|
|||||||
- release
|
- release
|
||||||
- linux
|
- linux
|
||||||
needs:
|
needs:
|
||||||
- job: linux-package
|
- job: linux-package-tar
|
||||||
artifacts: true
|
artifacts: true
|
||||||
- job: windows-package
|
- job: windows-package-zip
|
||||||
|
artifacts: true
|
||||||
|
- job: windows-package-exe
|
||||||
|
artifacts: true
|
||||||
|
- job: build-users-doc
|
||||||
|
artifacts: true
|
||||||
|
- job: build-developers-doc
|
||||||
artifacts: true
|
artifacts: true
|
||||||
rules:
|
rules:
|
||||||
- if: $CI_COMMIT_TAG
|
- if: $CI_COMMIT_TAG
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- packages/pamhyr-gnulinux-amd64.tar.xz
|
- linux/pamhyr-gnulinux.tar.xz
|
||||||
- packages/pamhyr-win-amd64.exe
|
- windows/pamhyr-windows.zip
|
||||||
|
- windows/pamhyr-windows.exe
|
||||||
|
- doc/dev/documentation.pdf
|
||||||
|
- doc/users/documentation.pdf
|
||||||
script:
|
script:
|
||||||
- cd packages
|
- cd packages
|
||||||
release:
|
release:
|
||||||
@@ -210,11 +384,23 @@ tag-release:
|
|||||||
ref: '$CI_COMMIT_SHA'
|
ref: '$CI_COMMIT_SHA'
|
||||||
assets:
|
assets:
|
||||||
links:
|
links:
|
||||||
- name: 'GNU/Linux amd64 (tar.xz)'
|
- name: 'GNU/Linux (tar.xz)'
|
||||||
url: '${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/packages/pamhyr-gnulinux-amd64.tar.xz'
|
url: '${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/linux/pamhyr-gnulinux.tar.xz'
|
||||||
filepath: '/packages/pamhyr-gnulinux-amd64.tar.xz'
|
filepath: '/linux/pamhyr-gnulinux.tar.xz'
|
||||||
link_type: 'package'
|
link_type: 'package'
|
||||||
- name: 'Windows amd64 (exe)'
|
- name: 'Windows (exe)'
|
||||||
url: '${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/packages/pamhyr-win-amd64.exe'
|
url: '${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/windows/pamhyr-windows.exe'
|
||||||
filepath: '/packages/pamhyr-win-amd64.exe'
|
filepath: '/windows/pamhyr-windows.exe'
|
||||||
link_type: 'package'
|
link_type: 'package'
|
||||||
|
- name: 'Windows (zip)'
|
||||||
|
url: '${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/windows/pamhyr-windows.zip'
|
||||||
|
filepath: '/windows/pamhyr-windows.zip'
|
||||||
|
link_type: 'package'
|
||||||
|
- name: 'User documentations (pdf)'
|
||||||
|
url: '${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/doc/users/documentation.pdf'
|
||||||
|
filepath: '/doc/users/documentation.pdf'
|
||||||
|
link_type: 'other'
|
||||||
|
- name: 'Dev documentations (pdf)'
|
||||||
|
url: '${CI_PROJECT_URL}/-/jobs/${CI_JOB_ID}/artifacts/raw/doc/dev/documentation.pdf'
|
||||||
|
filepath: '/doc/dev/documentation.pdf'
|
||||||
|
link_type: 'other'
|
||||||
@@ -47,5 +47,4 @@ pip3 install -r requirements.txt
|
|||||||
|
|
||||||
# Run pamhyr
|
# Run pamhyr
|
||||||
./src/pamhyr.py
|
./src/pamhyr.py
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
echo " PDF documentation.org"
|
||||||
|
emacs -nw --batch \
|
||||||
|
--eval "(require 'org)" \
|
||||||
|
--eval "(require 'ox-latex)" \
|
||||||
|
--eval "(load-file \"../tools/setup.el\")" \
|
||||||
|
--file ./documentation.org \
|
||||||
|
-f org-latex-export-to-pdf
|
||||||
|
|
||||||
|
echo " HTML documentation.org"
|
||||||
|
emacs -nw --batch \
|
||||||
|
--eval "(require 'org)" \
|
||||||
|
--eval "(require 'ox-latex)" \
|
||||||
|
--eval "(require 'ox-html)" \
|
||||||
|
--eval "(load-file \"../tools/setup.el\")" \
|
||||||
|
--file ./documentation.org \
|
||||||
|
-f org-html-export-to-html
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../tools/ref.bib
|
||||||
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 34 KiB |
@@ -0,0 +1,163 @@
|
|||||||
|
\ProvidesClass{Pamhyr}[Pamhyr class]
|
||||||
|
\NeedsTeXFormat{LaTeX2e}
|
||||||
|
\ProcessOptions\relax
|
||||||
|
\LoadClass[11pt,a4paper]{article}
|
||||||
|
|
||||||
|
\usepackage[hmargin=2cm, vmargin=3cm]{geometry}
|
||||||
|
\usepackage[british,UKenglish,USenglish,english,american]{babel}
|
||||||
|
\usepackage[T1]{fontenc}
|
||||||
|
\usepackage{times}
|
||||||
|
\usepackage[usenames,dvipsnames]{xcolor}
|
||||||
|
\usepackage[absolute]{textpos}
|
||||||
|
\usepackage{titlesec}
|
||||||
|
\usepackage{amssymb}
|
||||||
|
\usepackage{tcolorbox}
|
||||||
|
|
||||||
|
\usepackage{enumitem}
|
||||||
|
\setlist[enumerate]{itemsep=-0.5em}
|
||||||
|
\setlist[itemize]{itemsep=-0.5em}
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% Bibtex
|
||||||
|
%%
|
||||||
|
|
||||||
|
\bibliographystyle{plain}
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% Colors
|
||||||
|
%%
|
||||||
|
|
||||||
|
\definecolor{primary}{HTML}{212121}
|
||||||
|
\definecolor{lightheadings}{HTML}{5c5c5c}
|
||||||
|
\definecolor{headings}{HTML}{212121}
|
||||||
|
\definecolor{links}{HTML}{e12121}
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% Title
|
||||||
|
%%
|
||||||
|
|
||||||
|
\setlength{\columnsep}{20pt}
|
||||||
|
\setlength{\parskip}{0pt} %% inter paragraph space
|
||||||
|
|
||||||
|
\renewcommand{\maketitle}{
|
||||||
|
{
|
||||||
|
\centering
|
||||||
|
{
|
||||||
|
\fontsize{35}{40}
|
||||||
|
\selectfont
|
||||||
|
\scshape
|
||||||
|
Pamhyr2 \\
|
||||||
|
\medskip
|
||||||
|
}
|
||||||
|
{
|
||||||
|
%\centering
|
||||||
|
\scshape
|
||||||
|
\fontsize{20pt}{24pt}
|
||||||
|
\selectfont
|
||||||
|
A graphical user interface for 1D hydro-sedimentary modelling
|
||||||
|
of rivers \\
|
||||||
|
\medskip
|
||||||
|
}
|
||||||
|
\rule{3cm}{0.4pt}\\
|
||||||
|
\vspace{0.3cm}
|
||||||
|
{
|
||||||
|
%\centering
|
||||||
|
\scshape
|
||||||
|
\fontsize{26pt}{24pt}
|
||||||
|
\selectfont
|
||||||
|
\@title \\
|
||||||
|
Document licence: GPLv3 \\
|
||||||
|
\medskip
|
||||||
|
\includegraphics[width=3cm]{../images/GPLv3_Logo.png} \\
|
||||||
|
\medskip
|
||||||
|
\fontsize{14pt}{16pt}
|
||||||
|
\selectfont
|
||||||
|
© \@author \\
|
||||||
|
\medskip
|
||||||
|
}
|
||||||
|
{
|
||||||
|
%\centering
|
||||||
|
%\scshape
|
||||||
|
\fontsize{12pt}{14pt}
|
||||||
|
\selectfont
|
||||||
|
\@date
|
||||||
|
%\medskip
|
||||||
|
}\\
|
||||||
|
\vspace{0.3cm}
|
||||||
|
\rule{3cm}{0.4pt}\\
|
||||||
|
\vspace{0.3cm}
|
||||||
|
{
|
||||||
|
\begin{minipage}[h]{0.24\textwidth}
|
||||||
|
\includegraphics[width=4cm]{../../src/View/ui/ressources/Logo-INRAE.png}
|
||||||
|
\end{minipage}
|
||||||
|
\begin{minipage}[h]{0.24\textwidth}
|
||||||
|
\includegraphics[width=4cm]{../images/riverly.png}
|
||||||
|
\end{minipage}
|
||||||
|
}\\
|
||||||
|
\vspace{0.3cm}
|
||||||
|
%%\rule{\textwidth}{0.4pt}
|
||||||
|
%%\newpage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% Texttt
|
||||||
|
%%
|
||||||
|
|
||||||
|
\usepackage[htt]{hyphenat} % Make texttt split at end of line
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% Verbatim
|
||||||
|
%%
|
||||||
|
|
||||||
|
\AtBeginEnvironment{verbatim}{\footnotesize}
|
||||||
|
|
||||||
|
%% Add box arrond of verbatim
|
||||||
|
\BeforeBeginEnvironment{verbatim}{\begin{tcolorbox}[boxsep=0pt, left=0.1cm, right=0.1cm, arc=0pt, boxrule=0.5pt, colback=white]}%
|
||||||
|
\AfterEndEnvironment{verbatim}{\end{tcolorbox}}%
|
||||||
|
|
||||||
|
\makeatletter
|
||||||
|
\AtBeginEnvironment{verbatim}{\dontdofcolorbox}
|
||||||
|
|
||||||
|
\def\dontdofcolorbox{\renewcommand\fcolorbox[4][]{##4}}
|
||||||
|
\makeatother
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% Source code blocks
|
||||||
|
%%
|
||||||
|
|
||||||
|
%% Use minted
|
||||||
|
\usepackage{minted}
|
||||||
|
\usemintedstyle{tango}
|
||||||
|
\setminted[c]{fontsize=\footnotesize,encoding=utf8,linenos}
|
||||||
|
\setminted[c++]{breaklines,fontsize=\footnotesize,encoding=utf8,linenos}
|
||||||
|
\setminted[python]{breaklines,fontsize=\footnotesize,encoding=utf8,linenos}
|
||||||
|
\setminted[shell]{breaklines,fontsize=\footnotesize,encoding=utf8}
|
||||||
|
\setminted[scheme]{breaklines,fontsize=\footnotesize,encoding=utf8}
|
||||||
|
\setminted[commun-lisp]{breaklines,fontsize=\footnotesize,encoding=utf8}
|
||||||
|
\setminted[text]{breaklines,fontsize=\footnotesize,encoding=utf8}
|
||||||
|
\setminted[llvm]{breaklines,fontsize=\footnotesize,encoding=utf8}
|
||||||
|
|
||||||
|
%% Add box arrond of minted
|
||||||
|
\BeforeBeginEnvironment{minted}{\begin{tcolorbox}[boxsep=0pt, left=0.1cm, right=0.1cm, arc=0pt, boxrule=0.5pt, colback=white]}%
|
||||||
|
\AfterEndEnvironment{minted}{\end{tcolorbox}}%
|
||||||
|
|
||||||
|
\makeatletter
|
||||||
|
\AtBeginEnvironment{minted}{\dontdofcolorbox}
|
||||||
|
|
||||||
|
\def\dontdofcolorbox{\renewcommand\fcolorbox[4][]{##4}}
|
||||||
|
\makeatother
|
||||||
|
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% Water mark
|
||||||
|
%%
|
||||||
|
|
||||||
|
%% FIXME: Delete me for the first realease
|
||||||
|
\usepackage{draftwatermark}
|
||||||
|
\SetWatermarkLightness{0.8}
|
||||||
|
\SetWatermarkAngle{25}
|
||||||
|
\SetWatermarkScale{3}
|
||||||
|
\SetWatermarkFontSize{1cm}
|
||||||
|
\SetWatermarkText{Work in progress}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# latex.org -- Pamhyr documentation latex config
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
#+LaTeX_CLASS: PamhyrDoc
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
# macro.org -- Pamhyr documentation macro
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Constant name
|
||||||
|
#+MACRO: oldPamhyr PAMHyR
|
||||||
|
#+MACRO: Pamhyr Pamhyr2
|
||||||
|
#+MACRO: Mage Mage
|
||||||
|
#+MACRO: Rubarbe RubarBE
|
||||||
|
#+MACRO: Inrae INRAE
|
||||||
|
#+MACRO: latex \LaTeX
|
||||||
|
|
||||||
|
# Information
|
||||||
|
#+MACRO: version (eval (pamhyr-version))
|
||||||
|
#+MACRO: current-file (eval (pamhyr-current-file))
|
||||||
|
|
||||||
|
# Special format
|
||||||
|
#+MACRO: file =$1=
|
||||||
|
|
||||||
|
# Biblio
|
||||||
|
#+MACRO: cite [cite:$1]
|
||||||
|
#+MACRO: biblio \bibliography{documentation}
|
||||||
|
|
||||||
|
# Wrapper
|
||||||
|
#+NAME: attr_wrap
|
||||||
|
#+HEADER: :var width="\\textwidth"
|
||||||
|
#+HEADER: :var caption=""
|
||||||
|
#+HEADER: :var smallcaption=""
|
||||||
|
#+HEADER: :var name=""
|
||||||
|
#+HEADER: :var data=""
|
||||||
|
#+HEADER: :var float="nil"
|
||||||
|
#+BEGIN_SRC sh :results output :exports none
|
||||||
|
echo "#+CAPTION[$smallcaption]: $caption"
|
||||||
|
echo "#+NAME: $name"
|
||||||
|
echo "#+ATTR_LATEX: :width $width :float $float"
|
||||||
|
echo "$data"
|
||||||
|
#+END_SRC
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
(require 'org)
|
||||||
|
(require 'subr-x)
|
||||||
|
|
||||||
|
;; LaTeX config
|
||||||
|
|
||||||
|
(add-to-list
|
||||||
|
'org-latex-classes
|
||||||
|
'("PamhyrDoc"
|
||||||
|
"\\documentclass{../tools/PamhyrDoc}"
|
||||||
|
("\\section{%s}" . "\\section*{%s}")
|
||||||
|
("\\subsection{%s}" . "\\subsection*{%s}")
|
||||||
|
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
|
||||||
|
("\\paragraph{%s}" . "\\paragraph*{%s}")
|
||||||
|
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
|
||||||
|
|
||||||
|
(setq org-confirm-babel-evaluate nil)
|
||||||
|
(setq org-latex-caption-above nil)
|
||||||
|
|
||||||
|
(org-babel-do-load-languages
|
||||||
|
'org-babel-load-languages
|
||||||
|
(add-to-list 'org-babel-load-languages '(shell . t)))
|
||||||
|
|
||||||
|
(org-babel-do-load-languages
|
||||||
|
'org-babel-load-languages
|
||||||
|
(add-to-list 'org-babel-load-languages '(dot . t)))
|
||||||
|
|
||||||
|
(org-babel-do-load-languages
|
||||||
|
'org-babel-load-languages
|
||||||
|
(add-to-list 'org-babel-load-languages '(python . t)))
|
||||||
|
|
||||||
|
(add-to-list 'org-latex-packages-alist '("" "minted"))
|
||||||
|
(setq org-latex-listings 'minted)
|
||||||
|
(setq org-src-fontify-natively t)
|
||||||
|
|
||||||
|
(setq org-latex-pdf-process
|
||||||
|
'("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
|
||||||
|
"bibtex documentation"
|
||||||
|
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
|
||||||
|
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
|
||||||
|
|
||||||
|
;; Citations
|
||||||
|
|
||||||
|
(org-add-link-type
|
||||||
|
"cite" 'ebib
|
||||||
|
(lambda (path desc format)
|
||||||
|
(cond
|
||||||
|
((eq format 'html)
|
||||||
|
(format "(<cite>%s</cite>)" path))
|
||||||
|
((eq format 'latex)
|
||||||
|
(if (or (not desc) (equal 0 (search "cite:" desc)))
|
||||||
|
(format "\\cite{%s}" path)
|
||||||
|
(format "\\cite[%s][%s]{%s}"
|
||||||
|
(cadr (split-string desc ";"))
|
||||||
|
(car (split-string desc ";")) path))))))
|
||||||
|
|
||||||
|
;; Functools
|
||||||
|
|
||||||
|
(defun pamhyr-version ()
|
||||||
|
"Return the contents of the pamhyr version file."
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents "../../VERSION")
|
||||||
|
(buffer-string)))
|
||||||
|
|
||||||
|
(defun pamhyr-current-file ()
|
||||||
|
(let ((lst (split-string (buffer-file-name) "/")))
|
||||||
|
(string-join (nthcdr (- (length lst) 3) lst) "/")))
|
||||||
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 150 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
@@ -0,0 +1,434 @@
|
|||||||
|
1 0 0 8 31090.0000
|
||||||
|
31090.0000 0.0000 23.7300
|
||||||
|
31090.0000 2.5000 20.2800 rg
|
||||||
|
31090.0000 2.5000 19.2900
|
||||||
|
31090.0000 4.4000 19.2900
|
||||||
|
31090.0000 10.7000 19.5900
|
||||||
|
31090.0000 10.7000 20.5900 rd
|
||||||
|
31090.0000 14.5000 21.7100
|
||||||
|
31090.0000 17.6000 23.7300
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
2 0 0 8 31165.0000
|
||||||
|
31165.0000 0.0000 22.8400
|
||||||
|
31165.0000 2.5000 20.1300 rg
|
||||||
|
31165.0000 2.5000 19.2300
|
||||||
|
31165.0000 4.4000 19.2300
|
||||||
|
31165.0000 10.7000 19.5300
|
||||||
|
31165.0000 10.7000 20.5300 rd
|
||||||
|
31165.0000 14.5000 21.7500
|
||||||
|
31165.0000 17.6000 23.5000
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
3 0 0 10 31425.0000
|
||||||
|
31425.0000 -1.0000 22.8000
|
||||||
|
31425.0000 0.0000 21.9000
|
||||||
|
31425.0000 1.7000 20.3600 rg
|
||||||
|
31425.0000 2.5000 19.6300
|
||||||
|
31425.0000 2.5000 19.0300
|
||||||
|
31425.0000 4.4000 19.0300
|
||||||
|
31425.0000 10.7000 19.3300
|
||||||
|
31425.0000 10.7000 20.3300 rd
|
||||||
|
31425.0000 14.5000 21.9200
|
||||||
|
31425.0000 17.6000 23.4200
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
4 0 0 10 31590.0000
|
||||||
|
31590.0000 -1.0000 22.7500
|
||||||
|
31590.0000 0.0000 22.0500
|
||||||
|
31590.0000 1.6700 20.2200 rg
|
||||||
|
31590.0000 2.5000 19.3100
|
||||||
|
31590.0000 2.5000 18.9000
|
||||||
|
31590.0000 4.4000 18.9000
|
||||||
|
31590.0000 10.7000 19.2000
|
||||||
|
31590.0000 10.7000 20.2000 rd
|
||||||
|
31590.0000 14.5000 22.0200
|
||||||
|
31590.0000 17.6000 23.2500
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
5 0 0 10 31780.0000
|
||||||
|
31780.0000 -1.0000 22.7000
|
||||||
|
31780.0000 0.0000 22.0500
|
||||||
|
31780.0000 1.6000 20.0500 rg
|
||||||
|
31780.0000 2.5000 18.9400
|
||||||
|
31780.0000 2.5000 18.7500
|
||||||
|
31780.0000 4.4000 18.7500
|
||||||
|
31780.0000 10.7000 19.0500
|
||||||
|
31780.0000 10.7000 20.0500 rd
|
||||||
|
31780.0000 14.5000 22.1400
|
||||||
|
31780.0000 17.6000 23.0000
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
6 0 0 9 31874.0000
|
||||||
|
31874.0000 0.0000 22.9900
|
||||||
|
31874.0000 0.0000 22.6900
|
||||||
|
31874.0000 2.5000 19.6900 rg
|
||||||
|
31874.0000 2.5000 18.6900
|
||||||
|
31874.0000 4.4000 18.6900
|
||||||
|
31874.0000 10.7000 18.9900
|
||||||
|
31874.0000 10.7000 19.9900 rd
|
||||||
|
31874.0000 14.5000 22.1900
|
||||||
|
31874.0000 17.6000 22.9900
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
7 0 0 7 31875.0000 PontRD101m
|
||||||
|
31875.0000 0.5400 21.8900
|
||||||
|
31875.0000 2.5000 19.6900 rg
|
||||||
|
31875.0000 2.5000 18.6900
|
||||||
|
31875.0000 4.4000 18.6900
|
||||||
|
31875.0000 10.7000 18.9900
|
||||||
|
31875.0000 10.7000 19.9900 rd
|
||||||
|
31875.0000 13.8900 21.8900
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
8 0 0 7 31885.0000 PontRD101v
|
||||||
|
31885.0000 0.5400 21.8900
|
||||||
|
31885.0000 2.5000 19.6900 rg
|
||||||
|
31885.0000 2.5000 18.6900
|
||||||
|
31885.0000 4.4000 18.6900
|
||||||
|
31885.0000 10.7000 18.9900
|
||||||
|
31885.0000 10.7000 19.9900 rd
|
||||||
|
31885.0000 13.8900 21.8900
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
9 0 0 9 31886.0000
|
||||||
|
31886.0000 0.0000 22.9900
|
||||||
|
31886.0000 0.0000 22.6900
|
||||||
|
31886.0000 2.5000 19.6900 rg
|
||||||
|
31886.0000 2.5000 18.6900
|
||||||
|
31886.0000 4.4000 18.6900
|
||||||
|
31886.0000 10.7000 18.9900
|
||||||
|
31886.0000 10.7000 19.9900 rd
|
||||||
|
31886.0000 14.5000 22.1900
|
||||||
|
31886.0000 17.6000 22.9900
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
10 0 0 13 32015.0000
|
||||||
|
32015.0000 0.0000 22.6400
|
||||||
|
32015.0000 0.2000 22.2200
|
||||||
|
32015.0000 1.3000 20.9900
|
||||||
|
32015.0000 2.0000 19.8800 rg
|
||||||
|
32015.0000 3.0000 18.6600
|
||||||
|
32015.0000 3.0000 18.5800
|
||||||
|
32015.0000 5.5000 18.5800
|
||||||
|
32015.0000 10.0000 18.9100
|
||||||
|
32015.0000 11.5000 19.2500
|
||||||
|
32015.0000 11.5000 20.0800 rd
|
||||||
|
32015.0000 15.1000 22.0600
|
||||||
|
32015.0000 17.6000 22.5100
|
||||||
|
32015.0000 18.0000 22.8100
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
11 0 0 13 32205.0000
|
||||||
|
32205.0000 0.0000 22.3300
|
||||||
|
32205.0000 0.2000 22.1800
|
||||||
|
32205.0000 1.5000 21.0600
|
||||||
|
32205.0000 2.5000 19.7700 rg
|
||||||
|
32205.0000 3.6000 18.5100
|
||||||
|
32205.0000 3.6000 18.4500
|
||||||
|
32205.0000 6.9000 18.4500
|
||||||
|
32205.0000 8.8000 19.0500
|
||||||
|
32205.0000 12.5000 19.5700 rd
|
||||||
|
32205.0000 12.5000 20.1800
|
||||||
|
32205.0000 15.8000 21.9000
|
||||||
|
32205.0000 18.1000 22.4000
|
||||||
|
32205.0000 18.6000 22.5500
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
12 0 0 13 32460.0000
|
||||||
|
32460.0000 0.0000 22.1500
|
||||||
|
32460.0000 0.3000 22.1300
|
||||||
|
32460.0000 1.8000 21.1600
|
||||||
|
32460.0000 3.0000 19.6400 rg
|
||||||
|
32460.0000 4.4000 18.3100
|
||||||
|
32460.0000 4.4000 18.2800
|
||||||
|
32460.0000 8.7000 18.2800
|
||||||
|
32460.0000 10.4000 19.2400 rd
|
||||||
|
32460.0000 13.7000 19.9900
|
||||||
|
32460.0000 13.7000 20.3300
|
||||||
|
32460.0000 16.8000 21.6800
|
||||||
|
32460.0000 18.9000 22.2500
|
||||||
|
32460.0000 19.3000 22.5500
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
13 0 0 13 32655.0000
|
||||||
|
32655.0000 0.0000 22.4500
|
||||||
|
32655.0000 0.3000 22.0900
|
||||||
|
32655.0000 2.1000 21.2300
|
||||||
|
32655.0000 3.4000 19.5300 rg
|
||||||
|
32655.0000 5.0000 18.1600
|
||||||
|
32655.0000 5.0000 18.1400
|
||||||
|
32655.0000 10.1000 18.1400
|
||||||
|
32655.0000 11.6000 19.3900 rd
|
||||||
|
32655.0000 14.7000 20.3100
|
||||||
|
32655.0000 14.7000 20.4300
|
||||||
|
32655.0000 17.5000 21.5200
|
||||||
|
32655.0000 19.4000 22.1400
|
||||||
|
32655.0000 19.8000 22.4500
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
14 0 0 13 32755.0000
|
||||||
|
32755.0000 0.0000 22.4500
|
||||||
|
32755.0000 0.3000 22.0900
|
||||||
|
32755.0000 2.1000 21.2300
|
||||||
|
32755.0000 3.4000 19.5300 rg
|
||||||
|
32755.0000 4.0000 18.0500
|
||||||
|
32755.0000 5.0000 18.0100
|
||||||
|
32755.0000 10.1000 18.0100
|
||||||
|
32755.0000 13.0000 19.3900 rd
|
||||||
|
32755.0000 14.7000 20.3100
|
||||||
|
32755.0000 14.7000 20.4300
|
||||||
|
32755.0000 17.5000 21.5200
|
||||||
|
32755.0000 19.4000 22.1400
|
||||||
|
32755.0000 19.8000 22.4500
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
15 0 0 10 32770.0000 PontA2
|
||||||
|
32770.0000 0.0000 25.0000
|
||||||
|
32770.0000 1.9000 25.0000
|
||||||
|
32770.0000 1.9000 21.2700
|
||||||
|
32770.0000 3.3000 19.4700 rg
|
||||||
|
32770.0000 5.0000 18.0100
|
||||||
|
32770.0000 10.5000 18.0100
|
||||||
|
32770.0000 12.0000 19.4700 rd
|
||||||
|
32770.0000 19.4000 21.4700
|
||||||
|
32770.0000 19.4000 25.0000
|
||||||
|
32770.0000 20.3000 25.0000
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
16 0 0 10 32800.0000 PontA2
|
||||||
|
32800.0000 0.0000 25.0000
|
||||||
|
32800.0000 1.9000 25.0000
|
||||||
|
32800.0000 1.9000 21.2700
|
||||||
|
32800.0000 3.3000 19.4700 rg
|
||||||
|
32800.0000 5.0000 18.0100
|
||||||
|
32800.0000 10.5000 18.0100
|
||||||
|
32800.0000 12.0000 19.4700 rd
|
||||||
|
32800.0000 19.4000 21.4700
|
||||||
|
32800.0000 19.4000 25.0000
|
||||||
|
32800.0000 20.3000 25.0000
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
17 0 0 13 32820.0000
|
||||||
|
32820.0000 0.0000 22.4500
|
||||||
|
32820.0000 0.3000 22.0900
|
||||||
|
32820.0000 2.1000 21.2300
|
||||||
|
32820.0000 3.4000 19.5300 rg
|
||||||
|
32820.0000 4.0000 18.0500
|
||||||
|
32820.0000 5.0000 18.0100
|
||||||
|
32820.0000 10.1000 18.0100
|
||||||
|
32820.0000 13.0000 19.3900 rd
|
||||||
|
32820.0000 14.7000 20.3100
|
||||||
|
32820.0000 14.7000 20.4300
|
||||||
|
32820.0000 17.5000 21.5200
|
||||||
|
32820.0000 19.4000 22.1400
|
||||||
|
32820.0000 19.8000 22.4500
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
18 0 0 11 32915.0000
|
||||||
|
32915.0000 0.0000 22.5500
|
||||||
|
32915.0000 0.4000 21.9500
|
||||||
|
32915.0000 1.7000 21.2200
|
||||||
|
32915.0000 2.4000 20.9700
|
||||||
|
32915.0000 3.8000 19.4100 rg
|
||||||
|
32915.0000 3.9000 19.3100
|
||||||
|
32915.0000 5.8000 18.0100
|
||||||
|
32915.0000 11.0000 18.0100
|
||||||
|
32915.0000 12.4000 19.3400 rd
|
||||||
|
32915.0000 19.4000 21.9900
|
||||||
|
32915.0000 19.7000 22.5500
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
19 0 0 10 33140.0000
|
||||||
|
33140.0000 0.4000 21.7700
|
||||||
|
33140.0000 1.9000 20.7600
|
||||||
|
33140.0000 2.7000 20.5100
|
||||||
|
33140.0000 4.2000 19.1500 rg
|
||||||
|
33140.0000 4.3000 19.0600
|
||||||
|
33140.0000 6.4000 17.9200
|
||||||
|
33140.0000 11.3000 17.9200
|
||||||
|
33140.0000 12.6000 19.1400 rd
|
||||||
|
33140.0000 18.9000 21.8700
|
||||||
|
33140.0000 19.2000 22.1800
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
20 0 0 10 33425.0000
|
||||||
|
33425.0000 0.0000 21.6800
|
||||||
|
33425.0000 0.5000 21.5300
|
||||||
|
33425.0000 2.2000 20.1600
|
||||||
|
33425.0000 3.0000 19.9400
|
||||||
|
33425.0000 4.8000 18.8200 rg
|
||||||
|
33425.0000 4.9000 18.7500
|
||||||
|
33425.0000 7.2000 17.8000
|
||||||
|
33425.0000 11.7000 17.8000
|
||||||
|
33425.0000 12.8000 18.8800 rd
|
||||||
|
33425.0000 18.2000 21.6800
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
21 0 0 10 33685.0000
|
||||||
|
33685.0000 0.0000 21.5300
|
||||||
|
33685.0000 0.5000 21.3200
|
||||||
|
33685.0000 2.4000 19.6200
|
||||||
|
33685.0000 3.3000 19.4200
|
||||||
|
33685.0000 5.2000 18.5300 rg
|
||||||
|
33685.0000 5.4000 18.4700
|
||||||
|
33685.0000 7.9000 17.7000
|
||||||
|
33685.0000 12.0000 17.7000
|
||||||
|
33685.0000 12.9000 18.6500 rd
|
||||||
|
33685.0000 17.6000 21.5300
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
22 0 0 9 33920.0000
|
||||||
|
33920.0000 0.6000 20.9800
|
||||||
|
33920.0000 2.6000 19.1300
|
||||||
|
33920.0000 3.6000 18.9400
|
||||||
|
33920.0000 5.7000 18.2600 rg
|
||||||
|
33920.0000 5.8000 18.2200
|
||||||
|
33920.0000 8.5000 17.6000
|
||||||
|
33920.0000 12.3000 17.6000
|
||||||
|
33920.0000 13.1000 18.4400 rd
|
||||||
|
33920.0000 17.0000 21.1300
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
23 0 0 9 34095.0000
|
||||||
|
34095.0000 0.6000 20.9500
|
||||||
|
34095.0000 2.7000 18.7700
|
||||||
|
34095.0000 3.8000 18.5900
|
||||||
|
34095.0000 6.0000 18.0600 rg
|
||||||
|
34095.0000 6.1000 18.0300
|
||||||
|
34095.0000 9.0000 17.5300
|
||||||
|
34095.0000 12.5000 17.5300
|
||||||
|
34095.0000 13.2000 18.2800 rd
|
||||||
|
34095.0000 16.6000 20.9800
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
24 0 0 10 34295.0000
|
||||||
|
34295.0000 0.0000 21.3600
|
||||||
|
34295.0000 0.6000 20.8300
|
||||||
|
34295.0000 2.4000 18.3500
|
||||||
|
34295.0000 3.5000 18.1900
|
||||||
|
34295.0000 5.8000 17.8300 rg
|
||||||
|
34295.0000 6.5000 17.3400
|
||||||
|
34295.0000 9.5000 17.3600
|
||||||
|
34295.0000 12.8000 17.4100
|
||||||
|
34295.0000 14.0000 18.1000 rd
|
||||||
|
34295.0000 16.1000 21.3600
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
25 0 0 10 34334.0000 amontPontThivencel
|
||||||
|
34334.0000 0.0000 21.3600
|
||||||
|
34334.0000 0.6000 20.8300
|
||||||
|
34334.0000 2.4000 18.3500
|
||||||
|
34334.0000 3.5000 18.1900
|
||||||
|
34334.0000 5.8000 17.8300 rg
|
||||||
|
34334.0000 6.5000 17.3400
|
||||||
|
34334.0000 9.5000 17.3600
|
||||||
|
34334.0000 12.8000 17.4100
|
||||||
|
34334.0000 14.0000 18.1000 rd
|
||||||
|
34334.0000 16.1000 21.1300
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
26 0 0 7 34335.0000 PontmThivencelle
|
||||||
|
34335.0000 2.9000 20.7400
|
||||||
|
34335.0000 2.9000 18.2900 rg
|
||||||
|
34335.0000 6.4000 17.7900
|
||||||
|
34335.0000 9.6000 17.2600
|
||||||
|
34335.0000 12.8000 17.2600
|
||||||
|
34335.0000 12.8000 18.3100 rd
|
||||||
|
34335.0000 12.8000 20.7400
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
27 0 0 7 34343.0000 PontvThivencelle
|
||||||
|
34343.0000 2.9000 20.7400
|
||||||
|
34343.0000 2.9000 18.2900 rg
|
||||||
|
34343.0000 6.4000 17.7900
|
||||||
|
34343.0000 9.6000 17.2600
|
||||||
|
34343.0000 12.8000 17.2600
|
||||||
|
34343.0000 12.8000 18.2900 rd
|
||||||
|
34343.0000 12.8000 20.7400
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
28 0 0 10 34345.0000 avalPontThivencell
|
||||||
|
34345.0000 0.0000 21.3600
|
||||||
|
34345.0000 0.6000 20.8300
|
||||||
|
34345.0000 2.4000 18.3500
|
||||||
|
34345.0000 3.5000 18.1900
|
||||||
|
34345.0000 5.8000 17.8300 rg
|
||||||
|
34345.0000 6.5000 17.3400
|
||||||
|
34345.0000 9.5000 17.2600
|
||||||
|
34345.0000 12.8000 17.4100
|
||||||
|
34345.0000 14.0000 18.1000 rd
|
||||||
|
34345.0000 16.1000 21.1300
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
29 0 0 7 34405.0000
|
||||||
|
34405.0000 0.0000 21.1400
|
||||||
|
34405.0000 2.9000 17.8400 rg
|
||||||
|
34405.0000 6.4000 17.4400
|
||||||
|
34405.0000 9.6000 17.2000
|
||||||
|
34405.0000 12.8000 17.2200
|
||||||
|
34405.0000 13.9000 17.8400 rd
|
||||||
|
34405.0000 19.0000 21.0000
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
30 0 0 7 34535.0000
|
||||||
|
34535.0000 0.0000 20.5900
|
||||||
|
34535.0000 2.9000 17.7400 rg
|
||||||
|
34535.0000 6.4000 17.2400
|
||||||
|
34535.0000 9.6000 17.0300
|
||||||
|
34535.0000 12.8000 17.0300
|
||||||
|
34535.0000 13.5000 17.7400 rd
|
||||||
|
34535.0000 15.8000 20.6000
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
31 0 0 7 34705.0000
|
||||||
|
34705.0000 0.0000 20.5000
|
||||||
|
34705.0000 2.9000 17.6100 rg
|
||||||
|
34705.0000 6.4000 17.1100
|
||||||
|
34705.0000 9.6000 16.8500
|
||||||
|
34705.0000 12.8000 16.8500
|
||||||
|
34705.0000 14.0000 18.0000 rd
|
||||||
|
34705.0000 16.2000 20.5300
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
32 0 0 7 34825.0000
|
||||||
|
34825.0000 0.0000 20.6200
|
||||||
|
34825.0000 2.9000 17.5200 rg
|
||||||
|
34825.0000 6.4000 17.0200
|
||||||
|
34825.0000 9.6000 16.7100
|
||||||
|
34825.0000 12.8000 16.7100
|
||||||
|
34825.0000 13.5000 17.5200 rd
|
||||||
|
34825.0000 16.2000 20.5000
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
33 0 0 7 34995.0000
|
||||||
|
34995.0000 0.0000 20.3900
|
||||||
|
34995.0000 2.9000 17.3900 rg
|
||||||
|
34995.0000 6.4000 16.8900
|
||||||
|
34995.0000 9.6000 16.5300
|
||||||
|
34995.0000 12.8000 16.5300
|
||||||
|
34995.0000 13.6000 17.4300 rd
|
||||||
|
34995.0000 16.2000 20.3200
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
34 0 0 7 35135.0000
|
||||||
|
35135.0000 0.0000 20.1600
|
||||||
|
35135.0000 2.9000 17.2900 rg
|
||||||
|
35135.0000 6.4000 16.7900
|
||||||
|
35135.0000 9.6000 16.4300
|
||||||
|
35135.0000 12.8000 16.4300
|
||||||
|
35135.0000 13.9000 17.3700 rd
|
||||||
|
35135.0000 16.2000 20.0600
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
35 0 0 7 35360.0000
|
||||||
|
35360.0000 0.0000 19.8600
|
||||||
|
35360.0000 2.9000 17.1200 rg
|
||||||
|
35360.0000 6.4000 16.6200
|
||||||
|
35360.0000 9.6000 16.2600
|
||||||
|
35360.0000 12.8000 16.2600
|
||||||
|
35360.0000 13.7000 17.1200 rd
|
||||||
|
35360.0000 16.2000 19.4600
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
36 0 0 7 35580.0000
|
||||||
|
35580.0000 0.0000 20.0000
|
||||||
|
35580.0000 2.9000 16.9500 rg
|
||||||
|
35580.0000 3.0000 16.0900
|
||||||
|
35580.0000 11.5000 16.0500
|
||||||
|
35580.0000 20.0000 16.0900
|
||||||
|
35580.0000 21.0000 17.0300 rd
|
||||||
|
35580.0000 23.0000 19.5000
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
37 0 0 7 35920.0000
|
||||||
|
35920.0000 0.0000 20.0000
|
||||||
|
35920.0000 2.2000 16.0200 rg
|
||||||
|
35920.0000 3.0000 14.5500
|
||||||
|
35920.0000 11.5000 14.5000
|
||||||
|
35920.0000 20.0000 14.5500
|
||||||
|
35920.0000 20.9000 16.0200 rd
|
||||||
|
35920.0000 23.0000 19.5000
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
38 0 0 7 36270.0000 S1
|
||||||
|
36270.0000 0.0000 20.0000
|
||||||
|
36270.0000 1.8000 17.0100 rg
|
||||||
|
36270.0000 3.0000 15.0800
|
||||||
|
36270.0000 11.5000 15.0500
|
||||||
|
36270.0000 20.0000 15.0800
|
||||||
|
36270.0000 21.3000 17.0100 rd
|
||||||
|
36270.0000 23.0000 19.5000
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
|
39 0 0 7 36271.0000 S1bis
|
||||||
|
36271.0000 0.0000 20.0000
|
||||||
|
36271.0000 1.8000 17.0100 rg
|
||||||
|
36271.0000 3.0000 13.0800
|
||||||
|
36271.0000 11.5000 13.0500
|
||||||
|
36271.0000 20.0000 13.0800
|
||||||
|
36271.0000 21.3000 17.0100 rd
|
||||||
|
36271.0000 23.0000 19.5000
|
||||||
|
999.9990 999.9990 999.9990
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
0:00:00:00 15
|
||||||
|
0:00:01:00 15
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
0:00:00:00 5,53
|
||||||
|
0:11:37:00 5,72
|
||||||
|
0:16:17:00 5,82
|
||||||
|
0:22:57:00 5,92
|
||||||
|
1:00:00:00 6,6
|
||||||
|
1:00:57:00 8,04
|
||||||
|
1:02:29:00 14,3
|
||||||
|
1:04:38:00 24,4
|
||||||
|
1:08:48:00 40
|
||||||
|
1:11:27:00 46,3
|
||||||
|
1:13:47:00 48,8
|
||||||
|
1:16:07:00 47,9
|
||||||
|
1:17:17:00 44,8
|
||||||
|
1:20:23:00 27,8
|
||||||
|
1:21:57:00 24,3
|
||||||
|
2:01:15:00 19,2
|
||||||
|
2:05:15:00 15,8
|
||||||
|
2:11:25:00 11,5
|
||||||
|
2:11:57:00 11,1
|
||||||
|
2:13:17:00 10,5
|
||||||
|
2:19:07:00 9,84
|
||||||
|
2:23:59:00 8,43
|
||||||
|
3:04:51:00 7,02
|
||||||
|
3:09:43:00 5,61
|
||||||
|
3:14:35:00 5,53
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
**************** SINGULARITES **********************
|
||||||
|
*BieSec Nb Longueur Cote dev Cote charg Coef deb Impression
|
||||||
|
*===---===----------==========----------==========-----------------------------
|
||||||
|
*****************************************************
|
||||||
|
* Bief n° 1
|
||||||
|
*****************************************************
|
||||||
|
* Ouvrage au pk 36270.0 seuil_aval
|
||||||
|
*SeuilR type D
|
||||||
|
D 1 36270.00 18.250 15.500 0.000 0.400 99999.000 seuil palplanches
|
||||||
|
* Ouvrage au pk 31875.0 PontRS101
|
||||||
|
*OrificeR type O
|
||||||
|
O 1 31875.00 9.660 18.710 21.890 0.400 9999.000
|
||||||
|
*SeuilR type D
|
||||||
|
D 1 31875.00 14.000 22.890 0.000 0.400 99999.000
|
||||||
|
* Ouvrage au pk 34335.0 PontThivencelle
|
||||||
|
*SeuilR type D
|
||||||
|
D 1 34335.00 13.000 21.740 0.000 0.400 99999.000
|
||||||
|
*OrificeR type O
|
||||||
|
O 1 34335.00 9.070 17.280 20.740 0.400 9999.000
|
||||||
|
*****************************************************
|
||||||
|
* Bief n° 3
|
||||||
|
*****************************************************
|
||||||
|
* Ouvrage au pk 0.0 Orifice
|
||||||
|
*OrificeR type O
|
||||||
|
*O 3 0.000 6.000 19.000 19.001 0.400 20.000 Clapet_001
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
$Clapet_001 clapet
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
0:00:00:00 4
|
||||||
|
0:00:01:00 4
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
16,03 0
|
||||||
|
16,13 1,29
|
||||||
|
16,23 3,64
|
||||||
|
16,33 6,7
|
||||||
|
16,43 10,31
|
||||||
|
16,53 14,41
|
||||||
|
16,63 18,94
|
||||||
|
16,73 23,87
|
||||||
|
16,83 29,16
|
||||||
|
16,93 34,79
|
||||||
|
17,03 40,75
|
||||||
|
17,13 47,01
|
||||||
|
17,23 53,57
|
||||||
|
17,33 60,4
|
||||||
|
17,43 67,5
|
||||||
|
17,53 74,86
|
||||||
|
17,63 82,47
|
||||||
|
17,73 90,33
|
||||||
|
17,83 98,41
|
||||||
|
17,93 106,73
|
||||||
|
18,03 115,26
|
||||||
|
18,13 124,01
|
||||||
|
18,23 132,98
|
||||||
|
18,33 142,14
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
0:00:00:00 4
|
||||||
|
0:01:16:48 4
|
||||||
|
0:16:00:00 50
|
||||||
|
1:11:46:28 36,8
|
||||||
|
2:07:27:22 23,3
|
||||||
|
5:04:24:58 13,8
|
||||||
|
10:03:00:06 9,38
|
||||||
|
20:02:19:58 7,29
|
||||||
|
30:01:54:37 5,97
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
0:00:00:00 4
|
||||||
|
0:01:49:48 4
|
||||||
|
0:16:00:00 35
|
||||||
|
1:11:25:48 25
|
||||||
|
2:07:30:00 16,4
|
||||||
|
5:03:55:12 9,66
|
||||||
|
10:03:00:00 6,56
|
||||||
|
27:00:54:00 4,91
|
||||||
|
30:01:48:36 4
|
||||||
|
31:06:00:00 4
|
||||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 23 KiB |
@@ -0,0 +1,201 @@
|
|||||||
|
%% LyX 2.0.2 created this file. For more info, see http://www.lyx.org/.
|
||||||
|
%% Do not edit unless you really know what you are doing.
|
||||||
|
\documentclass[12pt,french]{article}
|
||||||
|
\usepackage[T1]{fontenc}
|
||||||
|
\usepackage[latin9]{inputenc}
|
||||||
|
\usepackage{geometry}
|
||||||
|
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm,headheight=2cm,headsep=2cm,footskip=2cm}
|
||||||
|
\usepackage{textcomp}
|
||||||
|
\usepackage{graphicx}
|
||||||
|
\usepackage{hyperref}
|
||||||
|
|
||||||
|
\makeatletter
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
|
||||||
|
\newcommand{\noun}[1]{\textsc{#1}}
|
||||||
|
%% Because html converters don't know tabularnewline
|
||||||
|
\providecommand{\tabularnewline}{\\}
|
||||||
|
|
||||||
|
\makeatother
|
||||||
|
|
||||||
|
\usepackage{babel}
|
||||||
|
\addto\extrasfrench{%
|
||||||
|
\providecommand{\og}{\leavevmode\flqq~}%
|
||||||
|
\providecommand{\fg}{\ifdim\lastskip>\z@\unskip\fi~\frqq}%
|
||||||
|
}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
\includegraphics[width=5cm]{Logo-INRAE_Transparent.png}
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
Tutorial for Pamhyr2
|
||||||
|
|
||||||
|
January 2024
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\textbf{\LARGE 1D Modeling of the Hogneau River (Nord, France)}
|
||||||
|
|
||||||
|
using Pamhyr2
|
||||||
|
\par\end{center}{\LARGE \par}
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
{\large INRAE Lyon-Grenoble Auvergne-Rhône-Alpes}
|
||||||
|
\par\end{center}{\large \par}
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
Riverly, river hydraulics
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\begin{tabular}{lll}
|
||||||
|
Autors : & Pierre-Antoine Rouby & pierre-antoine.rouby@inrae.fr\tabularnewline
|
||||||
|
& Théophile TERRAZ & theophile.terraz@inrae.fr\tabularnewline
|
||||||
|
\end{tabular}
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
\pagebreak{}
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\tableofcontents{}
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
~
|
||||||
|
|
||||||
|
\pagebreak{}
|
||||||
|
|
||||||
|
\section{Introduction}
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
|
\pagebreak{}
|
||||||
|
|
||||||
|
\section{Install Pamhyr2}
|
||||||
|
|
||||||
|
Pamhyr2 can be downloaded from \url{https://gitlab.irstea.fr/theophile.terraz/pamhyr}.
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=15cm]{dl.png}
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
Use the GNU Linux or the Windows download button depending on your system. On windows, launch the installer. On Linux, unpack the archive and launch Pamhyr2.
|
||||||
|
|
||||||
|
|
||||||
|
\section{Create your first study}
|
||||||
|
|
||||||
|
On the main windows, click on \texttt{[Files] => [New Study]} to create a new study.
|
||||||
|
|
||||||
|
Click on \texttt{[River Network] => [Edit River Network]} to create the reaches of your river. In this window, you must define an oriented graph that represents the reaches of your river network: the edges are the reaches and the nodes are either upstream boundary conditions, downstream boundary conditions or junctions.
|
||||||
|
Press the \includegraphics[width=0.5cm]{gtk_add.png} to enter the \textit{add} mode. Create two nodes by clicking in the grey zone of the window, and create a link by clicking again on each node. press \includegraphics[width=0.5cm]{gtk_add.png} again to exit the \textit{add} mode. You created your first reach, with an upstream node and a downstream node. In the lower part of the \textit{Edit River Network} window you can rename the nodes and the reaches. As the reach you created is automaticaly selected, all the next steps will apply to this reach. The window should look like that:
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=15cm]{network.png}
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
Close the \textit{Edit River Network} window.
|
||||||
|
|
||||||
|
|
||||||
|
\section{Edit the river geometry}
|
||||||
|
|
||||||
|
Click on \texttt{[Geometry] => [Edit Geometry]} to define the geometry of the selected bief. Click on the \texttt{[Import]} button and select the file \texttt{Data/Bief\_1.st}. You should see:
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=15cm]{Geo.png}
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
On the left panel is a list of all the cross sections with their name and longitudinal abscisa. In the top left plot you can see the top view of the river, on the top right panel the longitudinal cross-section of the river and in the bottom plot you can see the selected cross-section (blue) along with the next one (dashed purple) and previous one (dashed black). You can move in the section list using the slider at the very right of the window.
|
||||||
|
|
||||||
|
You can edit the selected cross section by clicking on the \includegraphics[width=0.5cm]{"../../../src/View/ui/ressources/edit.png"} icon.
|
||||||
|
|
||||||
|
select the cross section named \textit{PontRD101m} and open the edition window. You should see:
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=15cm]{editsect.png}
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
On the left panel is the list of all the points of the section, with their coordinates, their name and their transversal absisa. The Z coordinate of the highest point is written in blue and the lowest in red. Points can have a name. If a point with the same name exists in every section in a reach, it forms a longitudinal line. For example, here we have \textit{rg} and \textit{rd} which represent the left bank and the right bank of the main chanel.
|
||||||
|
|
||||||
|
On the plot is a projection of the cross section. You can use \texttt{[ctrl + click]} to select a point in the plot. For now we don't have to change anything. You can close the cross section edition window and the geometry edition window.
|
||||||
|
|
||||||
|
\section{Edit the boundary conditions}
|
||||||
|
|
||||||
|
From the main window, click on \texttt{[Hydraulics] => [Boundary conditions and punctual contributions]}.You should see:
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=15cm]{boundary.png}
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
Use the \textit{add} button on the top left of the window to add a liquid boundary condition.
|
||||||
|
On the new line, click to select the whole line, double click to select the cell.
|
||||||
|
Select the \textit{Type} cell to give a name to the boundary condition. here, we will define the flow discharge mesured during the february 2002 flood. You can name this boundary condition "flood2002".
|
||||||
|
Select the \textit{Type} cell and use the combo box to put a Q(t) law.
|
||||||
|
Select the \textit{Node} cell and atribute this condition to the upstream node.
|
||||||
|
Names of the nodes are recalled in network in the right panel.
|
||||||
|
Now select the whole line and click on the edit button \includegraphics[width=0.5cm]{"../../../src/View/ui/ressources/edit.png"}. You opened the \textit{Edit Boundary Conditions} window.
|
||||||
|
On a text editor, open the \texttt{Data/Fevrier\_2002.txt} file. Copy the content of the file (for example with \textit{ctrl+a ctrl+c}) and paste it in the left panel of the \textit{Edit Boundary Conditions} window with \textit{ctrl+v}. You can now see the flow discharge curve:
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=15cm]{fev2002.png}
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
Close this window. Go back on the \textit{Boundary Conditions} window. Add a new line, give it a name, give it the textit{Z(T)} type and associate it to the downstream node of the network. Open the \textit{Edit Boundary Conditions} window (\includegraphics[width=0.5cm]{"../../../src/View/ui/ressources/edit.png"}). Add two lines. In the first one, enter time: 0.00.00 and Z: 15.000.
|
||||||
|
On the second one, time: 1.00.00 and Z: 15.000. It creates a constant downstream water elevation. For the computaion, Mage will extrapolate continuously the water elevation, that's why we only need to define one hour.
|
||||||
|
You can close the the \textit{Edit Boundary Conditions} and the \textit{Boundary Conditions} window.
|
||||||
|
|
||||||
|
\section{Create initial conditions}
|
||||||
|
|
||||||
|
From the main window, click on \texttt{[Hydraulics] => [Initial conditions]}.
|
||||||
|
Click on \texttt{Generate minimal height} and enter a height of 2 meters in the pop-up window to generate an initial water height condition that verify the folowing conditions: a water height of at least 2 meters and a decreasing water surface elevation from upstream to downstream. You should see:
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=15cm]{ic.png}
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
Close the \textit{Initial conditions} window.
|
||||||
|
|
||||||
|
|
||||||
|
\section{Edit friction coefficients}
|
||||||
|
|
||||||
|
From the main window, click on \texttt{[Hydraulics] => [Edit friction]}.
|
||||||
|
You fist have to define sets of Strickler coefficients. Click on \includegraphics[width=0.5cm]{"../../../src/View/ui/ressources/edit.png"} to open the \textit{Strickler} window. Here you can create couples of Strickler coefficients, the first one for the minor bed, the second one for the medium bed. Click on \textit{add} four times to create four new couple. Give them the folowing values:
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=15cm]{K.png}
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
Close the \textit{Strickler} window. On the \textit{Edit friction} window, add four lines with the button \includegraphics[width=0.5cm]{gtk_add.png} to create fous friction zones. Each zone is defined by a \textit{begin} and \textit{end} PK and a \textit{begin} and \textit{end} Strickler couple. The strickler coefficient couples inside a zone are interpolated from the \textit{begin} and \textit{end} couples. In our case, we will use constant coefficients per zone. Set the zones as follow:
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=15cm]{frictions.png}
|
||||||
|
\par\end{center}
|
||||||
|
|
||||||
|
\pagebreak{}
|
||||||
|
\end{document}
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
echo " PDF documentation.org"
|
||||||
|
emacs -nw --batch \
|
||||||
|
--eval "(require 'org)" \
|
||||||
|
--eval "(require 'ox-latex)" \
|
||||||
|
--eval "(load-file \"../tools/setup.el\")" \
|
||||||
|
--file ./documentation.org \
|
||||||
|
-f org-latex-export-to-pdf
|
||||||
|
|
||||||
|
echo " HTML documentation.org"
|
||||||
|
emacs -nw --batch \
|
||||||
|
--eval "(require 'org)" \
|
||||||
|
--eval "(require 'ox-latex)" \
|
||||||
|
--eval "(require 'ox-html)" \
|
||||||
|
--eval "(load-file \"../tools/setup.el\")" \
|
||||||
|
--file ./documentation.org \
|
||||||
|
-f org-html-export-to-html
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../tools/ref.bib
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#+STARTUP: indent
|
||||||
|
|
||||||
|
#+INCLUDE: ../tools/macro.org
|
||||||
|
#+INCLUDE: ../tools/latex.org
|
||||||
|
|
||||||
|
#+TITLE: User documentation
|
||||||
|
#+SUBTITLE: Version: {{{version}}}
|
||||||
|
#+AUTHOR: {{{INRAE}}}
|
||||||
|
|
||||||
|
#+OPTIONS: toc:t
|
||||||
|
#+LANGUAGE: UKenglish
|
||||||
|
|
||||||
|
* TODO Over view
|
||||||
|
* TODO Get started
|
||||||
|
** Installation
|
||||||
|
*** Linux
|
||||||
|
*** Windows
|
||||||
|
* TODO Usage
|
||||||
|
|
||||||
|
{{{biblio}}}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
PyQt5==5.15.4
|
||||||
|
PyQt5-Qt5==5.15.2
|
||||||
|
PyQt5-sip==12.12.2
|
||||||
|
PyQtWebEngine==5.15.6
|
||||||
|
QScintilla>=2.14.1
|
||||||
|
pyqtgraph>=0.12.1
|
||||||
|
matplotlib>=3.4.1
|
||||||
|
numpy>=1.24.2
|
||||||
|
colorama>=0.4.3
|
||||||
|
pyinstaller>=5.11.0
|
||||||
|
shapely>=2.0.1
|
||||||
|
lxml>=4.9.3
|
||||||
@@ -25,6 +25,7 @@ echo " *** SETUP ENV"
|
|||||||
|
|
||||||
python3 -m venv linux-pamhyr-venv
|
python3 -m venv linux-pamhyr-venv
|
||||||
. linux-pamhyr-venv/bin/activate
|
. linux-pamhyr-venv/bin/activate
|
||||||
|
pip3 install -U pip
|
||||||
pip3 install -r ../requirements.txt
|
pip3 install -r ../requirements.txt
|
||||||
|
|
||||||
echo " *** PYINSTALL"
|
echo " *** PYINSTALL"
|
||||||
@@ -43,18 +44,22 @@ cd $OLD_PWD
|
|||||||
|
|
||||||
echo " *** COPY DATA"
|
echo " *** COPY DATA"
|
||||||
|
|
||||||
mkdir -p dist/pamhyr/View/ui
|
mkdir -p dist/pamhyr/_internal/View/ui
|
||||||
mkdir -p dist/pamhyr/View/ui/Widgets
|
mkdir -p dist/pamhyr/_internal/View/ui/Widgets
|
||||||
cp -r ../src/View/ui/ressources/ dist/pamhyr/View/ui/
|
cp -r ../src/View/ui/ressources/ dist/pamhyr/_internal/View/ui/
|
||||||
cp -r ../src/View/ui/Widgets/*.ui dist/pamhyr/View/ui/Widgets/
|
cp -r ../src/View/ui/Widgets/*.ui dist/pamhyr/_internal/View/ui/Widgets/
|
||||||
cp -r ../src/View/ui/*.ui dist/pamhyr/View/ui/
|
cp -r ../src/View/ui/*.ui dist/pamhyr/_internal/View/ui/
|
||||||
|
|
||||||
mkdir -p dist/pamhyr/lang
|
mkdir -p dist/pamhyr/lang
|
||||||
cp -r ../src/lang/*.qm dist/pamhyr/lang/
|
cp -r ../src/lang/*.qm dist/pamhyr/lang/
|
||||||
|
|
||||||
cp ../VERSION dist/pamhyr/
|
mkdir dist/pamhyr/_internal/
|
||||||
cp ../AUTHORS dist/pamhyr/
|
#cp ../VERSION dist/pamhyr/_internal/
|
||||||
cp ../LICENSE dist/pamhyr/
|
VERSION=$(cat ../VERSION)
|
||||||
|
echo "local-build-$VERSION" > dist/pamhyr/_internal/VERSION
|
||||||
|
cp ../AUTHORS dist/pamhyr/_internal/
|
||||||
|
cp ../LICENSE dist/pamhyr/_internal/
|
||||||
|
cp ../src/motd.txt dist/pamhyr/_internal/
|
||||||
|
|
||||||
mkdir -p dist/pamhyr/mage/
|
mkdir -p dist/pamhyr/mage/
|
||||||
cp ../mage/mage dist/pamhyr/mage/
|
cp ../mage/mage dist/pamhyr/mage/
|
||||||
@@ -65,6 +70,18 @@ mkdir -p dist/pamhyr/tests_cases/
|
|||||||
mkdir -p dist/pamhyr/tests_cases/Saar
|
mkdir -p dist/pamhyr/tests_cases/Saar
|
||||||
cp ../tests_cases/Saar/Saar.pamhyr dist/pamhyr/tests_cases/Saar/
|
cp ../tests_cases/Saar/Saar.pamhyr dist/pamhyr/tests_cases/Saar/
|
||||||
|
|
||||||
|
mkdir -p dist/pamhyr/doc/
|
||||||
|
cp ../doc/dev/documentation.pdf dist/pamhyr/doc/Pamhyr2-dev.pdf
|
||||||
|
cp ../doc/dev/documentation.html dist/pamhyr/doc/Pamhyr2-dev.html
|
||||||
|
|
||||||
|
cp ../doc/users/documentation.pdf dist/pamhyr/doc/Pamhyr2-users.pdf
|
||||||
|
cp ../doc/users/documentation.html dist/pamhyr/doc/Pamhyr2-users.html
|
||||||
|
|
||||||
|
mkdir -p dist/pamhyr/doc/images
|
||||||
|
cp ../doc/users/images/* dist/pamhyr/doc/images/
|
||||||
|
cp ../doc/dev/images/* dist/pamhyr/doc/images/
|
||||||
|
cp ../doc/images/* dist/pamhyr/doc/images/
|
||||||
|
|
||||||
echo " *** MAKE SRC PACKAGE"
|
echo " *** MAKE SRC PACKAGE"
|
||||||
|
|
||||||
OLD_PWD=$PWD
|
OLD_PWD=$PWD
|
||||||
@@ -76,11 +93,11 @@ mv ../pamhyr-src.tar.gz ./
|
|||||||
|
|
||||||
echo " *** MAKE BIN PACKAGE"
|
echo " *** MAKE BIN PACKAGE"
|
||||||
|
|
||||||
OLD_PWD=$PWD
|
# OLD_PWD=$PWD
|
||||||
cd dist/
|
# cd dist/
|
||||||
tar --xz -cf pamhyr-gnulinux-amd64.tar.xz pamhyr --checkpoint=.100
|
# tar --xz -cf pamhyr-gnulinux-amd64.tar.xz pamhyr --checkpoint=.100
|
||||||
cd $OLD_PWD
|
# cd $OLD_PWD
|
||||||
|
|
||||||
mv dist/pamhyr-gnulinux-amd64.tar.xz ./
|
# mv dist/pamhyr-gnulinux-amd64.tar.xz ./
|
||||||
|
|
||||||
echo " *** DONE"
|
echo " *** DONE"
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
rem windows.bat -- Pamhyr Windows batch for windows version building
|
||||||
|
rem Copyright (C) 2023 INRAE
|
||||||
|
rem
|
||||||
|
rem This program is free software: you can redistribute it and/or modify
|
||||||
|
rem it under the terms of the GNU General Public License as published by
|
||||||
|
rem the Free Software Foundation, either version 3 of the License, or
|
||||||
|
rem (at your option) any later version.
|
||||||
|
rem
|
||||||
|
rem This program is distributed in the hope that it will be useful,
|
||||||
|
rem but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
rem GNU General Public License for more details.
|
||||||
|
rem
|
||||||
|
rem You should have received a copy of the GNU General Public License
|
||||||
|
rem along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
@ECHO ON
|
||||||
|
|
||||||
|
mkdir pamhyr\pamhyr\_internal
|
||||||
|
xcopy /s /e /y dist\pamhyr pamhyr\pamhyr
|
||||||
|
|
||||||
|
rem Copy data
|
||||||
|
mkdir pamhyr\pamhyr\_internal\lang
|
||||||
|
mkdir pamhyr\pamhyr\_internal\View\ui\ressources
|
||||||
|
mkdir pamhyr\pamhyr\_internal\View\ui\Widgets
|
||||||
|
|
||||||
|
rem UI
|
||||||
|
copy /y ..\src\View\ui\ressources\ pamhyr\pamhyr\_internal\View\ui\ressources
|
||||||
|
copy /y ..\src\View\ui\Widgets\*.ui pamhyr\pamhyr\_internal\View\ui\Widgets
|
||||||
|
copy /y ..\src\View\ui\*.ui pamhyr\pamhyr\_internal\View\ui\
|
||||||
|
|
||||||
|
rem Lang
|
||||||
|
copy /y ..\src\lang\*.qm pamhyr\pamhyr\_internal\lang\
|
||||||
|
|
||||||
|
rem Information
|
||||||
|
copy /y ..\VERSION pamhyr\pamhyr\_internal
|
||||||
|
copy /y ..\AUTHORS pamhyr\pamhyr\_internal
|
||||||
|
copy /y ..\LICENSE pamhyr\pamhyr\_internal
|
||||||
|
copy /y ..\src\motd.txt pamhyr\pamhyr\_internal
|
||||||
|
|
||||||
|
rem MAGE
|
||||||
|
mkdir pamhyr\mage
|
||||||
|
copy /y ..\mage-windows\mage.exe pamhyr\mage\
|
||||||
|
copy /y ..\mage-windows\mage_extraire.exe pamhyr\mage\
|
||||||
|
copy /y ..\mage-windows\mailleurPF.exe pamhyr\mage\
|
||||||
|
|
||||||
|
rem Copy tests_cases
|
||||||
|
mkdir pamhyr\tests_cases
|
||||||
|
mkdir pamhyr\tests_cases\Saar
|
||||||
|
copy /y ..\tests_cases\Saar\Saar.pamhyr pamhyr\tests_cases\Saar\
|
||||||
|
|
||||||
|
rem Documentations
|
||||||
|
mkdir pamhyr\doc
|
||||||
|
mkdir pamhyr\doc\images
|
||||||
|
copy /y ..\doc\users\documentation.pdf pamhyr\doc\Pamhyr2-users.pdf
|
||||||
|
copy /y ..\doc\dev\documentation.pdf pamhyr\doc\Pamhyr2-dev.pdf
|
||||||
|
copy /y ..\doc\users\documentation.html pamhyr\doc\Pamhyr2-users.html
|
||||||
|
copy /y ..\doc\dev\documentation.html pamhyr\doc\Pamhyr2-dev.html
|
||||||
|
copy /y ..\doc\users\images\* pamhyr\doc\images
|
||||||
|
copy /y ..\doc\dev\images\* pamhyr\doc\images
|
||||||
|
copy /y ..\doc\images\* pamhyr\doc\images
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
rem windows.bat -- Pamhyr Windows batch for windows version building
|
||||||
|
rem Copyright (C) 2023 INRAE
|
||||||
|
rem
|
||||||
|
rem This program is free software: you can redistribute it and/or modify
|
||||||
|
rem it under the terms of the GNU General Public License as published by
|
||||||
|
rem the Free Software Foundation, either version 3 of the License, or
|
||||||
|
rem (at your option) any later version.
|
||||||
|
rem
|
||||||
|
rem This program is distributed in the hope that it will be useful,
|
||||||
|
rem but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
rem GNU General Public License for more details.
|
||||||
|
rem
|
||||||
|
rem You should have received a copy of the GNU General Public License
|
||||||
|
rem along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
@ECHO ON
|
||||||
|
|
||||||
|
rem Make installer
|
||||||
|
"C:\Program Files (x86)\NSIS\makensis.exe" pamhyr.nsi
|
||||||
@@ -3,17 +3,17 @@
|
|||||||
!define LIC_NAME "LICENSE"
|
!define LIC_NAME "LICENSE"
|
||||||
!define APP_NAME "PAMHYR"
|
!define APP_NAME "PAMHYR"
|
||||||
|
|
||||||
Name "PAMHYR"
|
Name "Pamhyr2"
|
||||||
OutFile "pamhyr-win-amd64.exe"
|
OutFile "pamhyr-windows.exe"
|
||||||
LicenseData "..\LICENSE"
|
LicenseData "pamhyr\pamhyr\_internal\LICENSE"
|
||||||
LicenseText "I Agree"
|
LicenseText "I Agree"
|
||||||
|
|
||||||
RequestExecutionLevel admin
|
RequestExecutionLevel admin
|
||||||
|
|
||||||
Unicode True
|
Unicode True
|
||||||
InstallDir $PROGRAMFILES\PAMHYR
|
InstallDir $PROGRAMFILES\Pamhyr2
|
||||||
|
|
||||||
InstallDirRegKey HKLM "Software\PAMHYR" "Install_Dir"
|
InstallDirRegKey HKLM "Software\Pamhyr2" "Install_Dir"
|
||||||
|
|
||||||
Page license
|
Page license
|
||||||
Page components
|
Page components
|
||||||
@@ -23,35 +23,39 @@ Page instfiles
|
|||||||
UninstPage uninstConfirm
|
UninstPage uninstConfirm
|
||||||
UninstPage instfiles
|
UninstPage instfiles
|
||||||
|
|
||||||
Section "PAMHYR"
|
Section "Pamhyr2"
|
||||||
SectionIn RO
|
SectionIn RO
|
||||||
|
|
||||||
SetOutPath $INSTDIR
|
SetOutPath $INSTDIR
|
||||||
|
|
||||||
File /r "dist\pamhyr\*"
|
File /r "pamhyr\*"
|
||||||
|
|
||||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PAMHYR" "DisplayName" "NSIS PAMHYR"
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pamhyr2" "DisplayName" "NSIS Pamhyr2"
|
||||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PAMHYR" "UninstallString" "$INSTDIR\uninstall.exe"
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pamhyr2" "UninstallString" "$INSTDIR\uninstall.exe"
|
||||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PAMHYR" "NoModify" 1
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pamhyr2" "NoModify" 1
|
||||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PAMHYR" "NoRepair" 1
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pamhyr2" "NoRepair" 1
|
||||||
WriteUninstaller "$INSTDIR\uninstall.exe"
|
WriteUninstaller "$INSTDIR\uninstall.exe"
|
||||||
|
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
Section "Start Menu Shortcuts"
|
Section "Start Menu Shortcuts"
|
||||||
|
CreateDirectory "$SMPROGRAMS\Pamhyr2"
|
||||||
|
CreateShortcut "$SMPROGRAMS\Pamhyr2\Uninstall.lnk" "$INSTDIR\uninstall.exe"
|
||||||
|
CreateShortcut "$SMPROGRAMS\Pamhyr2\Pamhyr2.lnk" "$INSTDIR\pamhyr\pamhyr.exe"
|
||||||
|
SectionEnd
|
||||||
|
|
||||||
CreateDirectory "$SMPROGRAMS\PAMHYR"
|
Section "Desktop Shortcuts"
|
||||||
CreateShortcut "$SMPROGRAMS\PAMHYR\Uninstall.lnk" "$INSTDIR\uninstall.exe"
|
SetShellVarContext all
|
||||||
CreateShortcut "$SMPROGRAMS\PAMHYR\PAMHYR.lnk" "$INSTDIR\pamhyr.exe"
|
CreateShortcut "$desktop\Pamhyr2.lnk" "$instdir\pamhyr\pamhyr.exe"
|
||||||
|
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
Section "Uninstall"
|
Section "Uninstall"
|
||||||
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PAMHYR"
|
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pamhyr2"
|
||||||
DeleteRegKey HKLM SOFTWARE\NSIS_PAMHYR
|
DeleteRegKey HKLM SOFTWARE\NSIS_Pamhyr2
|
||||||
|
|
||||||
Delete "$SMPROGRAMS\PAMHYR\*.lnk"
|
Delete "$SMPROGRAMS\Pamhyr2\*.lnk"
|
||||||
|
Delete "$desktop\Pamhyr2.lnk"
|
||||||
|
|
||||||
RMDir "$SMPROGRAMS\PAMHYR"
|
RMDir "$SMPROGRAMS\Pamhyr2"
|
||||||
RMDir /R "$INSTDIR"
|
RMDir /R "$INSTDIR"
|
||||||
SectionEnd
|
SectionEnd
|
||||||
@@ -81,13 +81,42 @@ wine pyinstaller ../src/pamhyr.py -y
|
|||||||
|
|
||||||
echo " *** COPY DATA"
|
echo " *** COPY DATA"
|
||||||
|
|
||||||
mkdir -p dist/pamhyr/View/ui
|
mkdir -p pamhyr
|
||||||
cp -r ../src/View/ui/ressources/ dist/pamhyr/View/ui/
|
mkdir -p pamhyr/pamhyr
|
||||||
cp -r ../src/View/ui/Widgets/*.ui dist/pamhyr/View/ui/
|
|
||||||
cp -r ../src/View/ui/*.ui dist/pamhyr/View/ui/
|
|
||||||
|
|
||||||
cp ../VERSION dist/pamhyr/
|
# Copy Pamhyr info
|
||||||
cp ../AUTHORS dist/pamhyr/
|
cp -v ../VERSION pamhyr/pamhyr/
|
||||||
|
cp -v ../AUTHORS pamhyr/pamhyr/
|
||||||
|
cp -v ../LICENSE pamhyr/pamhyr/
|
||||||
|
|
||||||
|
# Copy mage
|
||||||
|
mkdir -p pamhyr/mage
|
||||||
|
cp -v ../mage/* pamhyr/mage/
|
||||||
|
|
||||||
|
# Copy Pamhyr
|
||||||
|
cp -r dist/pamhyr pamhyr/
|
||||||
|
|
||||||
|
# Copy Pamhyr resources
|
||||||
|
mkdir -p pamhyr/pamhyr/View
|
||||||
|
mkdir -p pamhyr/pamhyr/View/ui
|
||||||
|
mkdir -p pamhyr/pamhyr/View/ui/Widgets
|
||||||
|
cp -r ../src/View/ui/*.ui pamhyr/pamhyr/View/ui/
|
||||||
|
cp -r ../src/View/ui/ressources/ pamhyr/pamhyr/View/ui
|
||||||
|
cp -r ../src/View/ui/Widgets/*.ui pamhyr/pamhyr/View/ui/Widgets
|
||||||
|
|
||||||
|
# Copy lang
|
||||||
|
mkdir -p pamhyr/pamhyr/lang
|
||||||
|
cp -r ../src/lang/*.qm pamhyr/pamhyr/lang
|
||||||
|
|
||||||
|
# Copy tests cases
|
||||||
|
mkdir -p pamhyr/tests_cases/
|
||||||
|
mkdir -p pamhyr/tests_cases/Saar
|
||||||
|
cp ../tests_cases/Saar/Saar.pamhyr pamhyr/tests_cases/Saar/
|
||||||
|
|
||||||
|
# Copy documentations
|
||||||
|
mkdir -p pamhyr/doc/
|
||||||
|
cp ../doc/users/documentation.pdf pamhyr/doc/Pamhyr2-users.pdf
|
||||||
|
cp ../doc/dev/documentation.pdf pamhyr/doc/Pamhyr2-dev.pdf
|
||||||
|
|
||||||
# Update TS and build QM files
|
# Update TS and build QM files
|
||||||
OLD_PWD=$PWD
|
OLD_PWD=$PWD
|
||||||
@@ -102,19 +131,19 @@ echo " *** MAKE PACKAGES"
|
|||||||
|
|
||||||
echo " TAR pamhyr-win-amd64.tar.xz"
|
echo " TAR pamhyr-win-amd64.tar.xz"
|
||||||
|
|
||||||
OLD_PWD=$PWD
|
# OLD_PWD=$PWD
|
||||||
cd dist/
|
# cd dist/
|
||||||
tar --xz -cf pamhyr-win-amd64.tar.xz pamhyr --checkpoint=.100
|
# tar --xz -cf pamhyr-win-amd64.tar.xz pamhyr --checkpoint=.100
|
||||||
cd $OLD_PWD
|
# cd $OLD_PWD
|
||||||
mv dist/pamhyr-win-amd64.tar.xz ./
|
# mv dist/pamhyr-win-amd64.tar.xz ./
|
||||||
|
|
||||||
echo " ZIP pamhyr-win-amd64.zip"
|
echo " ZIP pamhyr-win-amd64.zip"
|
||||||
|
|
||||||
OLD_PWD=$PWD
|
# OLD_PWD=$PWD
|
||||||
cd dist/
|
# cd dist/
|
||||||
zip -r pamhyr-win-amd64.zip pamhyr/
|
# zip -r pamhyr-win-amd64.zip pamhyr/
|
||||||
cd $OLD_PWD
|
# cd $OLD_PWD
|
||||||
mv dist/pamhyr-win-amd64.zip ./
|
# mv dist/pamhyr-win-amd64.zip ./
|
||||||
|
|
||||||
echo " *** MAKE INSTALLER"
|
echo " *** MAKE INSTALLER"
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
PyQt5==5.15.4
|
PyQt5==5.15.4
|
||||||
PyQt5-Qt5==5.15.2
|
PyQt5-Qt5==5.15.2
|
||||||
PyQt5-sip==12.8.1
|
PyQt5-sip==12.12.2
|
||||||
|
#PyQtWebEngine==5.15.6
|
||||||
|
QScintilla>=2.14.1
|
||||||
pyqtgraph>=0.12.1
|
pyqtgraph>=0.12.1
|
||||||
matplotlib>=3.4.1
|
matplotlib>=3.4.1
|
||||||
numpy>=1.24.2
|
numpy>=1.24.2
|
||||||
colorama>=0.4.3
|
colorama>=0.4.3
|
||||||
pyinstaller>=5.11.0
|
pyinstaller>=5.11.0
|
||||||
shapely>=2.0.1
|
shapely>=2.0.1
|
||||||
|
lxml>=4.9.3
|
||||||
@@ -20,12 +20,14 @@ from enum import Enum
|
|||||||
|
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
|
|
||||||
class STATUS(Enum):
|
class STATUS(Enum):
|
||||||
UNKNOWN = -1
|
UNKNOWN = -1
|
||||||
OK = 0
|
OK = 0
|
||||||
WARNING = 1
|
WARNING = 1
|
||||||
ERROR = 2
|
ERROR = 2
|
||||||
|
|
||||||
|
|
||||||
class AbstractModelChecker(object):
|
class AbstractModelChecker(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._name = ""
|
self._name = ""
|
||||||
@@ -62,6 +64,12 @@ class AbstractModelChecker(object):
|
|||||||
|
|
||||||
# Abstract function
|
# Abstract function
|
||||||
|
|
||||||
|
def _run(self, study):
|
||||||
|
from Model.Study import Study
|
||||||
|
|
||||||
|
thread_study = Study.open(study._filename)
|
||||||
|
self.run(thread_study)
|
||||||
|
|
||||||
def run(self, study):
|
def run(self, study):
|
||||||
"""Run checker function
|
"""Run checker function
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,9 @@ from Checker.Checker import AbstractModelChecker, STATUS
|
|||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
|
||||||
class MageNetworkGraphChecker(AbstractModelChecker):
|
class MageNetworkGraphChecker(AbstractModelChecker):
|
||||||
def __init__(self, connectivity = True):
|
def __init__(self, connectivity=True):
|
||||||
super(MageNetworkGraphChecker, self).__init__()
|
super(MageNetworkGraphChecker, self).__init__()
|
||||||
|
|
||||||
self._mode_conn = connectivity
|
self._mode_conn = connectivity
|
||||||
@@ -38,8 +39,10 @@ class MageNetworkGraphChecker(AbstractModelChecker):
|
|||||||
else:
|
else:
|
||||||
mode = "cycle"
|
mode = "cycle"
|
||||||
|
|
||||||
self._name = _translate("Checker", f"Mage network graph {mode} checker")
|
self._name = _translate(
|
||||||
self._description = _translate("Checker", "Check if the network graph is valid")
|
"Checker", f"Mage network graph {mode} checker")
|
||||||
|
self._description = _translate(
|
||||||
|
"Checker", "Check if the network graph is valid")
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def _connectivity(self, summary, status, graph):
|
def _connectivity(self, summary, status, graph):
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ class StudyNetworkReachChecker(AbstractModelChecker):
|
|||||||
super(StudyNetworkReachChecker, self).__init__()
|
super(StudyNetworkReachChecker, self).__init__()
|
||||||
|
|
||||||
self._name = _translate("Checker", "Study network reach checker")
|
self._name = _translate("Checker", "Study network reach checker")
|
||||||
self._description = _translate("Checker", "Check if exists at least one reach for study")
|
self._description = _translate(
|
||||||
|
"Checker", "Check if exists at least one reach for study")
|
||||||
|
|
||||||
def run(self, study):
|
def run(self, study):
|
||||||
if study is None:
|
if study is None:
|
||||||
@@ -54,12 +55,14 @@ class StudyNetworkReachChecker(AbstractModelChecker):
|
|||||||
self._status = STATUS.OK
|
self._status = STATUS.OK
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class StudyGeometryChecker(AbstractModelChecker):
|
class StudyGeometryChecker(AbstractModelChecker):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(StudyGeometryChecker, self).__init__()
|
super(StudyGeometryChecker, self).__init__()
|
||||||
|
|
||||||
self._name = _translate("Checker", "Study geometry checker")
|
self._name = _translate("Checker", "Study geometry checker")
|
||||||
self._description = _translate("Checker", "Check if exists geometry for each reach of study")
|
self._description = _translate(
|
||||||
|
"Checker", "Check if exists geometry for each reach of study")
|
||||||
self._reachs = []
|
self._reachs = []
|
||||||
|
|
||||||
def run(self, study):
|
def run(self, study):
|
||||||
@@ -128,6 +131,7 @@ class DummyWARNING(AbstractModelChecker):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class DummyERROR(AbstractModelChecker):
|
class DummyERROR(AbstractModelChecker):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(DummyERROR, self).__init__()
|
super(DummyERROR, self).__init__()
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
class AbstractModelComponent(object):
|
|
||||||
def __init__(self):
|
|
||||||
super(AbstractModelComponent, self).__init__()
|
|
||||||
|
|
||||||
def new(self, filename):
|
|
||||||
|
|
||||||
|
|
||||||
def export(self, filename):
|
|
||||||
@@ -20,17 +20,18 @@ import logging
|
|||||||
|
|
||||||
from tools import trace, timer, old_pamhyr_date_to_timestamp
|
from tools import trace, timer, old_pamhyr_date_to_timestamp
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class BoundaryCondition(SQLSubModel):
|
class BoundaryCondition(SQLSubModel):
|
||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
|
|
||||||
def __init__(self, id:int = -1, name:str = "",
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
status = None):
|
status=None):
|
||||||
super(BoundaryCondition, self).__init__()
|
super(BoundaryCondition, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -50,7 +51,7 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
BoundaryCondition._id_cnt = max(BoundaryCondition._id_cnt + 1, self.id)
|
BoundaryCondition._id_cnt = max(BoundaryCondition._id_cnt + 1, self.id)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE boundary_condition(
|
CREATE TABLE boundary_condition(
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
@@ -76,7 +77,7 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -101,7 +102,7 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
tab = data["tab"]
|
tab = data["tab"]
|
||||||
|
|
||||||
@@ -115,9 +116,9 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
t = row[2]
|
t = row[2]
|
||||||
ctor = cls._get_ctor_from_type(t)
|
ctor = cls._get_ctor_from_type(t)
|
||||||
bc = ctor(
|
bc = ctor(
|
||||||
id = row[0],
|
id=row[0],
|
||||||
name = row[1],
|
name=row[1],
|
||||||
status = data['status']
|
status=data['status']
|
||||||
)
|
)
|
||||||
|
|
||||||
bc.node = None
|
bc.node = None
|
||||||
@@ -143,7 +144,7 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
tab = data["tab"]
|
tab = data["tab"]
|
||||||
|
|
||||||
execute(f"DELETE FROM boundary_condition WHERE id = {self.id}")
|
execute(f"DELETE FROM boundary_condition WHERE id = {self.id}")
|
||||||
@@ -155,22 +156,22 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"boundary_condition(id, name, type, tab, node) "+
|
"boundary_condition(id, name, type, tab, node) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, '{self._sql_format(self._name)}', " +
|
f"{self.id}, '{self._db_format(self._name)}', " +
|
||||||
f"'{self._sql_format(self._type)}', '{tab}', {node}" +
|
f"'{self._db_format(self._type)}', '{tab}', {node}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
for d in self._data:
|
for d in self._data:
|
||||||
data0 = self._sql_format(str(d[0]))
|
data0 = self._db_format(str(d[0]))
|
||||||
data1 = self._sql_format(str(d[1]))
|
data1 = self._db_format(str(d[1]))
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"boundary_condition_data(ind, data0, data1, bc) "+
|
"boundary_condition_data(ind, data0, data1, bc) " +
|
||||||
f"VALUES ({ind}, '{data0}', {data1}, {self.id})"
|
f"VALUES ({ind}, '{data0}', {data1}, {self.id})"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
@@ -187,8 +188,13 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def time_convert(cls, data):
|
def time_convert(cls, data):
|
||||||
if type(data) == str and data.count(":") == 3:
|
if type(data) is str:
|
||||||
return old_pamhyr_date_to_timestamp(data)
|
if data.count(":") == 3:
|
||||||
|
return old_pamhyr_date_to_timestamp(data)
|
||||||
|
if data.count(":") == 2:
|
||||||
|
return old_pamhyr_date_to_timestamp("00:" + data)
|
||||||
|
if data.count(".") == 1:
|
||||||
|
return round(float(data))
|
||||||
|
|
||||||
return int(data)
|
return int(data)
|
||||||
|
|
||||||
@@ -246,7 +252,7 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
new_1 = self._default_1
|
new_1 = self._default_1
|
||||||
|
|
||||||
if len(header) != 0:
|
if len(header) != 0:
|
||||||
for i in [0,1]:
|
for i in [0, 1]:
|
||||||
for j in range(len(header)):
|
for j in range(len(header)):
|
||||||
if self._header[i] == header[j]:
|
if self._header[i] == header[j]:
|
||||||
if i == 0:
|
if i == 0:
|
||||||
@@ -259,13 +265,13 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
|
|
||||||
return (new_0, new_1)
|
return (new_0, new_1)
|
||||||
|
|
||||||
def add(self, index:int):
|
def add(self, index: int):
|
||||||
value = (self._default_0, self._default_1)
|
value = (self._default_0, self._default_1)
|
||||||
self._data.insert(index, value)
|
self._data.insert(index, value)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def insert(self, index:int, value):
|
def insert(self, index: int, value):
|
||||||
self._data.insert(index, value)
|
self._data.insert(index, value)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
@@ -301,11 +307,10 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
return self.data[index]
|
return self.data[index]
|
||||||
|
|
||||||
def get_range(self, _range):
|
def get_range(self, _range):
|
||||||
l = []
|
lst = []
|
||||||
for r in _range:
|
for r in _range:
|
||||||
l.append(r)
|
lst.append(r)
|
||||||
return l
|
return lst
|
||||||
|
|
||||||
|
|
||||||
def _set_i_c_v(self, index, column, value):
|
def _set_i_c_v(self, index, column, value):
|
||||||
v = list(self._data[index])
|
v = list(self._data[index])
|
||||||
@@ -313,22 +318,22 @@ class BoundaryCondition(SQLSubModel):
|
|||||||
self._data[index] = tuple(v)
|
self._data[index] = tuple(v)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def set_i_0(self, index:int, value):
|
def set_i_0(self, index: int, value):
|
||||||
self._set_i_c_v(index, 0, value)
|
self._set_i_c_v(index, 0, value)
|
||||||
|
|
||||||
def set_i_1(self, index:int, value):
|
def set_i_1(self, index: int, value):
|
||||||
self._set_i_c_v(index, 1, value)
|
self._set_i_c_v(index, 1, value)
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def convert(self, cls):
|
def convert(self, cls):
|
||||||
new = cls(name = self.name, status = self._status)
|
new = cls(name=self.name, status=self._status)
|
||||||
new.node = self.node
|
new.node = self.node
|
||||||
|
|
||||||
for i, _ in enumerate(self.data):
|
for i, _ in enumerate(self.data):
|
||||||
new.add(i)
|
new.add(i)
|
||||||
|
|
||||||
for i in [0,1]:
|
for i in [0, 1]:
|
||||||
for j in [0,1]:
|
for j in [0, 1]:
|
||||||
if self._header[i] == new.header[j]:
|
if self._header[i] == new.header[j]:
|
||||||
for ind, v in self.data:
|
for ind, v in self.data:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
from copy import copy
|
from copy import copy
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrList import PamhyrModelListWithTab
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition
|
from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition
|
||||||
@@ -30,46 +30,29 @@ from Model.BoundaryCondition.BoundaryConditionTypes import (
|
|||||||
Solid,
|
Solid,
|
||||||
)
|
)
|
||||||
|
|
||||||
class BoundaryConditionList(SQLSubModel):
|
|
||||||
|
class BoundaryConditionList(PamhyrModelListWithTab):
|
||||||
|
_tabs_list = ["liquid", "solid", "suspenssion"]
|
||||||
_sub_classes = [
|
_sub_classes = [
|
||||||
BoundaryCondition,
|
BoundaryCondition,
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, status = None):
|
|
||||||
super(BoundaryConditionList, self).__init__()
|
|
||||||
|
|
||||||
self._status = status
|
|
||||||
|
|
||||||
self._tabs = {
|
|
||||||
"liquid" : [],
|
|
||||||
"solid" : [],
|
|
||||||
"suspenssion" : []
|
|
||||||
}
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_load(cls, execute, data=None):
|
||||||
return cls._create_submodel(execute)
|
new = cls(status=data['status'])
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _sql_update(cls, execute, version):
|
|
||||||
return True
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _sql_load(cls, execute, data = None):
|
|
||||||
new = cls(status = data['status'])
|
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
for tab in new._tabs:
|
for tab in new._tabs:
|
||||||
data["tab"] = tab
|
data["tab"] = tab
|
||||||
new._tabs[tab] = BoundaryCondition._sql_load(
|
new._tabs[tab] = BoundaryCondition._db_load(
|
||||||
execute, data
|
execute, data
|
||||||
)
|
)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
execute("DELETE FROM boundary_condition")
|
execute("DELETE FROM boundary_condition")
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
@@ -78,85 +61,44 @@ class BoundaryConditionList(SQLSubModel):
|
|||||||
for tab in self._tabs:
|
for tab in self._tabs:
|
||||||
data["tab"] = tab
|
data["tab"] = tab
|
||||||
for bc in self._tabs[tab]:
|
for bc in self._tabs[tab]:
|
||||||
bc._sql_save(execute, data = data)
|
bc._db_save(execute, data=data)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def len(self, lst):
|
|
||||||
return len(self._tabs[lst])
|
|
||||||
|
|
||||||
def get_tab(self, lst):
|
|
||||||
return self._tabs[lst].copy()
|
|
||||||
|
|
||||||
def get(self, lst, row):
|
|
||||||
return self._tabs[lst][row]
|
|
||||||
|
|
||||||
def set(self, lst, row, new):
|
|
||||||
self._tabs[lst][row] = new
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def new(self, lst, index):
|
def new(self, lst, index):
|
||||||
n = NotDefined(status=self._status)
|
n = NotDefined(status=self._status)
|
||||||
self._tabs[lst].insert(index, n)
|
self._tabs[lst].insert(index, n)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def insert(self, lst, index, new):
|
|
||||||
self._tabs[lst].insert(index, new)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def delete(self, lst, bcs):
|
|
||||||
for bc in bcs:
|
|
||||||
self._tabs[lst].remove(bc)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def delete_i(self, lst, indexes):
|
|
||||||
bcs = list(
|
|
||||||
map(
|
|
||||||
lambda x: x[1],
|
|
||||||
filter(
|
|
||||||
lambda x: x[0] in indexes,
|
|
||||||
enumerate(self._tabs[lst])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.delete(lst, bcs)
|
|
||||||
|
|
||||||
def sort(self, lst, reverse=False, key=None):
|
|
||||||
self._tabs[lst].sort(reverse=reverse, key=key)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def move_up(self, lst, index):
|
|
||||||
if index < len(self._tabs[lst]):
|
|
||||||
next = index - 1
|
|
||||||
|
|
||||||
l = self._tabs[lst]
|
|
||||||
l[index], l[next] = l[next], l[index]
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def move_down(self, lst, index):
|
|
||||||
if index >= 0:
|
|
||||||
prev = index + 1
|
|
||||||
|
|
||||||
l = self._tabs[lst]
|
|
||||||
l[index], l[prev] = l[prev], l[index]
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def __copy__(self):
|
def __copy__(self):
|
||||||
new = BoundaryConditionList()
|
new = BoundaryConditionList()
|
||||||
|
|
||||||
for l in self._tabs:
|
for lst in self._tabs:
|
||||||
new.tabs[l] = self._tabs[l].copy()
|
new.tabs[lst] = self._tabs[lst].copy()
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def __deepcopy__(self):
|
def __deepcopy__(self):
|
||||||
new = BoundaryConditionList()
|
new = BoundaryConditionList()
|
||||||
|
|
||||||
for l in self._tabs:
|
for lst in self._tabs:
|
||||||
new.tabs[l] = self._tabs[l].deepcopy()
|
new.tabs[lst] = self._tabs[lst].deepcopy()
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return copy(self)
|
return copy(self)
|
||||||
|
|
||||||
|
def get_assoc_to_node(self, tab, node):
|
||||||
|
assoc = list(
|
||||||
|
filter(
|
||||||
|
lambda i: i.node is node,
|
||||||
|
self._tabs[tab]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(assoc) > 0:
|
||||||
|
return assoc[0]
|
||||||
|
|
||||||
|
return None
|
||||||
@@ -22,7 +22,7 @@ from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition
|
|||||||
|
|
||||||
|
|
||||||
class NotDefined(BoundaryCondition):
|
class NotDefined(BoundaryCondition):
|
||||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
super(NotDefined, self).__init__(id=id, name=name, status=status)
|
super(NotDefined, self).__init__(id=id, name=name, status=status)
|
||||||
|
|
||||||
self._type = "ND"
|
self._type = "ND"
|
||||||
@@ -32,9 +32,11 @@ class NotDefined(BoundaryCondition):
|
|||||||
def _default_0(self):
|
def _default_0(self):
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
|
|
||||||
class PonctualContribution(BoundaryCondition):
|
class PonctualContribution(BoundaryCondition):
|
||||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
super(PonctualContribution, self).__init__(id=id, name=name, status=status)
|
super(PonctualContribution, self).__init__(
|
||||||
|
id=id, name=name, status=status)
|
||||||
|
|
||||||
self._type = "PC"
|
self._type = "PC"
|
||||||
self._header = ["time", "discharge"]
|
self._header = ["time", "discharge"]
|
||||||
@@ -44,8 +46,9 @@ class PonctualContribution(BoundaryCondition):
|
|||||||
def compatibility(cls):
|
def compatibility(cls):
|
||||||
return ["liquid"]
|
return ["liquid"]
|
||||||
|
|
||||||
|
|
||||||
class TimeOverZ(BoundaryCondition):
|
class TimeOverZ(BoundaryCondition):
|
||||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
super(TimeOverZ, self).__init__(id=id, name=name, status=status)
|
super(TimeOverZ, self).__init__(id=id, name=name, status=status)
|
||||||
|
|
||||||
self._type = "TZ"
|
self._type = "TZ"
|
||||||
@@ -56,9 +59,11 @@ class TimeOverZ(BoundaryCondition):
|
|||||||
def compatibility(cls):
|
def compatibility(cls):
|
||||||
return ["liquid"]
|
return ["liquid"]
|
||||||
|
|
||||||
|
|
||||||
class TimeOverDischarge(BoundaryCondition):
|
class TimeOverDischarge(BoundaryCondition):
|
||||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
super(TimeOverDischarge, self).__init__(id=id, name=name, status=status)
|
super(TimeOverDischarge, self).__init__(
|
||||||
|
id=id, name=name, status=status)
|
||||||
|
|
||||||
self._type = "TD"
|
self._type = "TD"
|
||||||
self._header = ["time", "discharge"]
|
self._header = ["time", "discharge"]
|
||||||
@@ -68,8 +73,9 @@ class TimeOverDischarge(BoundaryCondition):
|
|||||||
def compatibility(cls):
|
def compatibility(cls):
|
||||||
return ["liquid"]
|
return ["liquid"]
|
||||||
|
|
||||||
|
|
||||||
class ZOverDischarge(BoundaryCondition):
|
class ZOverDischarge(BoundaryCondition):
|
||||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
super(ZOverDischarge, self).__init__(id=id, name=name, status=status)
|
super(ZOverDischarge, self).__init__(id=id, name=name, status=status)
|
||||||
|
|
||||||
self._type = "ZD"
|
self._type = "ZD"
|
||||||
@@ -86,7 +92,7 @@ class ZOverDischarge(BoundaryCondition):
|
|||||||
|
|
||||||
|
|
||||||
class Solid(BoundaryCondition):
|
class Solid(BoundaryCondition):
|
||||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
super(Solid, self).__init__(id=id, name=name, status=status)
|
super(Solid, self).__init__(id=id, name=name, status=status)
|
||||||
|
|
||||||
self.d50 = 0.002
|
self.d50 = 0.002
|
||||||
|
|||||||
@@ -45,8 +45,9 @@ def exception_message_box(exception):
|
|||||||
# Custom error #
|
# Custom error #
|
||||||
################
|
################
|
||||||
|
|
||||||
|
|
||||||
class ExeceptionWithMessageBox(Exception):
|
class ExeceptionWithMessageBox(Exception):
|
||||||
def __init__(self, title = "Exeception"):
|
def __init__(self, title="Exeception"):
|
||||||
self.title = title
|
self.title = title
|
||||||
|
|
||||||
def header(self):
|
def header(self):
|
||||||
@@ -72,7 +73,7 @@ class ExeceptionWithMessageBox(Exception):
|
|||||||
class NotImplementedMethodeError(ExeceptionWithMessageBox):
|
class NotImplementedMethodeError(ExeceptionWithMessageBox):
|
||||||
def __init__(self, obj, func):
|
def __init__(self, obj, func):
|
||||||
super(NotImplementedMethodeError, self).__init__(
|
super(NotImplementedMethodeError, self).__init__(
|
||||||
title = _translate("Exception", "Method not implemented")
|
title=_translate("Exception", "Method not implemented")
|
||||||
)
|
)
|
||||||
|
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
@@ -81,12 +82,16 @@ class NotImplementedMethodeError(ExeceptionWithMessageBox):
|
|||||||
self.alert()
|
self.alert()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
class_type = self.obj
|
||||||
|
if self.obj.__class__ != type:
|
||||||
|
class_type = self.obj.__class__
|
||||||
|
|
||||||
return (
|
return (
|
||||||
_translate("Exception", "Method") +
|
_translate("Exception", "Method") +
|
||||||
f" '{self.func.__name__}' " +
|
f" '{self.func.__name__}' " +
|
||||||
_translate("Exception", "not implemented") +
|
_translate("Exception", "not implemented") +
|
||||||
_translate("Exception", "for class") +
|
_translate("Exception", "for class") +
|
||||||
f" '{self.obj.__class__ if self.obj.__class__ != type else self.obj}'"
|
f" '{class_type}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
def header(self):
|
def header(self):
|
||||||
@@ -104,10 +109,11 @@ class NotImplementedMethodeError(ExeceptionWithMessageBox):
|
|||||||
f" '{self.obj.__class__}'"
|
f" '{self.obj.__class__}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class FileFormatError(ExeceptionWithMessageBox):
|
class FileFormatError(ExeceptionWithMessageBox):
|
||||||
def __init__(self, filename, reason):
|
def __init__(self, filename, reason):
|
||||||
super(FileFormatError, self).__init__(
|
super(FileFormatError, self).__init__(
|
||||||
title = _translate("Exception", "FileFormatError")
|
title=_translate("Exception", "FileFormatError")
|
||||||
)
|
)
|
||||||
|
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
@@ -137,7 +143,7 @@ class FileFormatError(ExeceptionWithMessageBox):
|
|||||||
class ClipboardFormatError(ExeceptionWithMessageBox):
|
class ClipboardFormatError(ExeceptionWithMessageBox):
|
||||||
def __init__(self, mime=None, header=None, data=None):
|
def __init__(self, mime=None, header=None, data=None):
|
||||||
super(ClipboardFormatError, self).__init__(
|
super(ClipboardFormatError, self).__init__(
|
||||||
title = _translate("Exception", "Clipboard format error")
|
title=_translate("Exception", "Clipboard format error")
|
||||||
)
|
)
|
||||||
|
|
||||||
self._mime = mime
|
self._mime = mime
|
||||||
|
|||||||
@@ -18,10 +18,11 @@
|
|||||||
|
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
|
||||||
|
|
||||||
class Friction(SQLSubModel):
|
class Friction(SQLSubModel):
|
||||||
def __init__(self, name:str = "", status = None):
|
def __init__(self, name: str = "", status=None):
|
||||||
super(Friction, self).__init__()
|
super(Friction, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -34,7 +35,7 @@ class Friction(SQLSubModel):
|
|||||||
self._end_strickler = None
|
self._end_strickler = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE friction(
|
CREATE TABLE friction(
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -53,11 +54,11 @@ class Friction(SQLSubModel):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
reach = data["parent"] # Reach object
|
reach = data["parent"] # Reach object
|
||||||
status = data["status"]
|
status = data["status"]
|
||||||
@@ -78,22 +79,21 @@ class Friction(SQLSubModel):
|
|||||||
es = next(filter(lambda s: s.id == row[4], stricklers))
|
es = next(filter(lambda s: s.id == row[4], stricklers))
|
||||||
|
|
||||||
# Create friction
|
# Create friction
|
||||||
sec = cls(status = status)
|
sec = cls(status=status)
|
||||||
sec.edge = reach
|
sec.edge = reach
|
||||||
sec.begin_kp = row[1]
|
sec.begin_kp = row[1]
|
||||||
sec.end_kp = row[2]
|
sec.end_kp = row[2]
|
||||||
sec.begin_strickler = bs
|
sec.begin_strickler = bs
|
||||||
sec.end_strickler = es
|
sec.end_strickler = es
|
||||||
|
|
||||||
new[ind] = sec
|
yield ind, sec
|
||||||
|
|
||||||
return new
|
def _db_save(self, execute, data=None):
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
|
||||||
ind = data["ind"]
|
ind = data["ind"]
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"friction(ind, begin_kp, end_kp, reach, begin_strickler, end_strickler) " +
|
"friction(ind, begin_kp, end_kp, " +
|
||||||
|
"reach, begin_strickler, end_strickler) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{ind}, {self._begin_kp}, {self._end_kp}, " +
|
f"{ind}, {self._begin_kp}, {self._end_kp}, " +
|
||||||
f"{self._edge.id}, " +
|
f"{self._edge.id}, " +
|
||||||
@@ -121,7 +121,7 @@ class Friction(SQLSubModel):
|
|||||||
self._edge = edge
|
self._edge = edge
|
||||||
if (edge is not None and
|
if (edge is not None and
|
||||||
self._begin_kp == 0.0 and
|
self._begin_kp == 0.0 and
|
||||||
self._end_kp == 0.0):
|
self._end_kp == 0.0):
|
||||||
self._begin_kp = self._edge.reach.get_kp_min()
|
self._begin_kp = self._edge.reach.get_kp_min()
|
||||||
self._end_kp = self._edge.reach.get_kp_max()
|
self._end_kp = self._edge.reach.get_kp_max()
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
@@ -129,6 +129,15 @@ class Friction(SQLSubModel):
|
|||||||
def has_edge(self):
|
def has_edge(self):
|
||||||
return self._edge is not None
|
return self._edge is not None
|
||||||
|
|
||||||
|
def has_coefficient(self):
|
||||||
|
return (
|
||||||
|
self._begin_strickler is not None and
|
||||||
|
self._end_strickler is not None
|
||||||
|
)
|
||||||
|
|
||||||
|
def is_full_defined(self):
|
||||||
|
return self.has_edge() and self.has_coefficient()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def begin_kp(self):
|
def begin_kp(self):
|
||||||
return self._begin_kp
|
return self._begin_kp
|
||||||
|
|||||||
@@ -21,118 +21,82 @@ import logging
|
|||||||
from copy import copy
|
from copy import copy
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
from Model.Tools.PamhyrList import PamhyrModelList
|
||||||
|
|
||||||
from Model.Friction.Friction import Friction
|
from Model.Friction.Friction import Friction
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
class FrictionList(SQLSubModel):
|
|
||||||
|
class FrictionList(PamhyrModelList):
|
||||||
_sub_classes = [
|
_sub_classes = [
|
||||||
Friction
|
Friction
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, status = None):
|
|
||||||
super(FrictionList, self).__init__()
|
|
||||||
|
|
||||||
self._status = status
|
|
||||||
self._frictions = []
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_update_0_0_1(cls, execute, version):
|
||||||
return cls._create_submodel(execute)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _sql_update_0_0_1(cls, execute, version):
|
|
||||||
execute("ALTER TABLE `section` RENAME TO `friction`")
|
execute("ALTER TABLE `section` RENAME TO `friction`")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
if version == "0.0.0":
|
if version == "0.0.0":
|
||||||
logger.info(f"Update friction TABLE from {version}")
|
logger.info(f"Update friction TABLE from {version}")
|
||||||
cls._sql_update_0_0_1(execute, version)
|
cls._db_update_0_0_1(execute, version)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = cls(status = data['status'])
|
new = cls(status=data['status'])
|
||||||
|
|
||||||
new._frictions = Friction._sql_load(
|
new._lst = Friction._db_load(
|
||||||
execute, data
|
execute, data
|
||||||
)
|
)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
|
frictions = self.lst
|
||||||
|
|
||||||
reach = data["reach"]
|
reach = data["reach"]
|
||||||
execute(f"DELETE FROM friction WHERE reach = {reach.id}")
|
execute(f"DELETE FROM friction WHERE reach = {reach.id}")
|
||||||
|
|
||||||
ok = True
|
ok = True
|
||||||
ind = 0
|
ind = 0
|
||||||
for friction in self._frictions:
|
for friction in frictions:
|
||||||
data["ind"] = ind
|
data["ind"] = ind
|
||||||
ok &= friction._sql_save(execute, data = data)
|
ok &= friction._db_save(execute, data=data)
|
||||||
ind += 1
|
ind += 1
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
|
|
||||||
def __len__(self):
|
def _get_frictions_list(self):
|
||||||
return len(self._frictions)
|
# Frictions list generator is type (int, Point) with the first
|
||||||
|
# element the index of the Point in list
|
||||||
@property
|
return list(
|
||||||
def frictions(self):
|
|
||||||
return self._frictions.copy()
|
|
||||||
|
|
||||||
def get(self, row):
|
|
||||||
return self._frictions[row]
|
|
||||||
|
|
||||||
def set(self, row, new):
|
|
||||||
self._frictions[row] = new
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def new(self, index):
|
|
||||||
n = Friction(status = self._status)
|
|
||||||
self._frictions.insert(index, n)
|
|
||||||
self._status.modified()
|
|
||||||
return n
|
|
||||||
|
|
||||||
def insert(self, index, new):
|
|
||||||
self._frictions.insert(index, new)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def delete(self, frictions):
|
|
||||||
for friction in frictions:
|
|
||||||
self._frictions.remove(friction)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def delete_i(self, indexes):
|
|
||||||
frictions = list(
|
|
||||||
map(
|
map(
|
||||||
lambda x: x[1],
|
lambda p: p[1],
|
||||||
filter(
|
sorted(
|
||||||
lambda x: x[0] in indexes,
|
self._lst,
|
||||||
enumerate(self._frictions)
|
key=lambda p: p[0]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.delete(frictions)
|
|
||||||
|
|
||||||
def sort(self, reverse=False, key=None):
|
@property
|
||||||
self._frictions.sort(reverse=reverse, key=key)
|
def lst(self):
|
||||||
|
if not isinstance(self._lst, list):
|
||||||
|
self._lst = self._get_frictions_list()
|
||||||
|
|
||||||
|
return self._lst
|
||||||
|
|
||||||
|
@property
|
||||||
|
def frictions(self):
|
||||||
|
return self.lst
|
||||||
|
|
||||||
|
def new(self, index):
|
||||||
|
n = Friction(status=self._status)
|
||||||
|
self._lst.insert(index, n)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
return n
|
||||||
def move_up(self, index):
|
|
||||||
if index < len(self._frictions):
|
|
||||||
next = index - 1
|
|
||||||
|
|
||||||
l = self._frictions
|
|
||||||
l[index], l[next] = l[next], l[index]
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def move_down(self, index):
|
|
||||||
if index >= 0:
|
|
||||||
prev = index + 1
|
|
||||||
|
|
||||||
l = self._frictions
|
|
||||||
l[index], l[prev] = l[prev], l[index]
|
|
||||||
self._status.modified()
|
|
||||||
@@ -18,8 +18,9 @@
|
|||||||
|
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
|
|
||||||
class Point(object):
|
class Point(object):
|
||||||
def __init__(self, name:str = "", profile=None, status = None):
|
def __init__(self, name: str = "", profile=None, status=None):
|
||||||
super(Point, self).__init__()
|
super(Point, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -28,7 +29,6 @@ class Point(object):
|
|||||||
self._profile = profile
|
self._profile = profile
|
||||||
self._sl = None
|
self._sl = None
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sl(self):
|
def sl(self):
|
||||||
if self._sl is None:
|
if self._sl is None:
|
||||||
@@ -40,8 +40,8 @@ class Point(object):
|
|||||||
def sl(self, sl):
|
def sl(self, sl):
|
||||||
if sl == self._profile.sl:
|
if sl == self._profile.sl:
|
||||||
self._sl = None
|
self._sl = None
|
||||||
|
else:
|
||||||
self._sl = sl
|
self._sl = sl
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ from math import dist
|
|||||||
|
|
||||||
from Model.Geometry.Point import Point
|
from Model.Geometry.Point import Point
|
||||||
|
|
||||||
|
|
||||||
class PointAC(Point):
|
class PointAC(Point):
|
||||||
def __init__(self, a:float = 0.0, c:float = 0.0,
|
def __init__(self, a: float = 0.0, c: float = 0.0,
|
||||||
name: str = "", status = None):
|
name: str = "", status=None):
|
||||||
super(PointXY, self).__init__(name = name, status = status)
|
super(PointXY, self).__init__(name=name, status=status)
|
||||||
|
|
||||||
self._a = float(a)
|
self._a = float(a)
|
||||||
self._c = float(c)
|
self._c = float(c)
|
||||||
|
|||||||
@@ -19,22 +19,24 @@
|
|||||||
from math import dist
|
from math import dist
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Geometry.Point import Point
|
from Model.Geometry.Point import Point
|
||||||
|
|
||||||
|
|
||||||
class PointXYZ(Point, SQLSubModel):
|
class PointXYZ(Point, SQLSubModel):
|
||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
|
|
||||||
def __init__(self, x:float = 0.0, y:float = 0.0, z:float = 0.0,
|
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0,
|
||||||
name:str = "", profile = None, status = None):
|
name: str = "", profile=None, status=None):
|
||||||
super(PointXYZ, self).__init__(name=name, profile=profile, status=status)
|
super(PointXYZ, self).__init__(
|
||||||
|
name=name, profile=profile, status=status)
|
||||||
|
|
||||||
self._x = float(x)
|
self._x = float(x)
|
||||||
self._y = float(y)
|
self._y = float(y)
|
||||||
self._z = float(z)
|
self._z = float(z)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE geometry_pointXYZ(
|
CREATE TABLE geometry_pointXYZ(
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -53,7 +55,7 @@ class PointXYZ(Point, SQLSubModel):
|
|||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
cls._update_submodel(execute, version)
|
cls._update_submodel(execute, version)
|
||||||
|
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
@@ -69,9 +71,7 @@ class PointXYZ(Point, SQLSubModel):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
points = []
|
|
||||||
|
|
||||||
status = data["status"]
|
status = data["status"]
|
||||||
profile = data["profile"]
|
profile = data["profile"]
|
||||||
|
|
||||||
@@ -81,10 +81,6 @@ class PointXYZ(Point, SQLSubModel):
|
|||||||
f"WHERE profile = {profile.id}"
|
f"WHERE profile = {profile.id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create points list
|
|
||||||
for _ in table:
|
|
||||||
points.append(None)
|
|
||||||
|
|
||||||
# Fill points list with new point
|
# Fill points list with new point
|
||||||
for row in table:
|
for row in table:
|
||||||
ind = row[0]
|
ind = row[0]
|
||||||
@@ -95,13 +91,13 @@ class PointXYZ(Point, SQLSubModel):
|
|||||||
sl = row[5]
|
sl = row[5]
|
||||||
|
|
||||||
new = cls(
|
new = cls(
|
||||||
name = name,
|
name=name,
|
||||||
x = x, y = y, z = z,
|
x=x, y=y, z=z,
|
||||||
profile = profile,
|
profile=profile,
|
||||||
status = status
|
status=status
|
||||||
)
|
)
|
||||||
|
|
||||||
if sl == -1 or sl == None:
|
if sl == -1 or sl is None:
|
||||||
new._sl = None
|
new._sl = None
|
||||||
else:
|
else:
|
||||||
new._sl = next(
|
new._sl = next(
|
||||||
@@ -111,11 +107,9 @@ class PointXYZ(Point, SQLSubModel):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
points[ind] = new
|
yield ind, new
|
||||||
|
|
||||||
return points
|
def _db_save(self, execute, data=None):
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
|
||||||
profile = data["profile"]
|
profile = data["profile"]
|
||||||
ind = data["ind"]
|
ind = data["ind"]
|
||||||
|
|
||||||
@@ -123,9 +117,9 @@ class PointXYZ(Point, SQLSubModel):
|
|||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT OR REPLACE INTO " +
|
"INSERT OR REPLACE INTO " +
|
||||||
"geometry_pointXYZ(ind, name, x, y, z, profile, sl) "+
|
"geometry_pointXYZ(ind, name, x, y, z, profile, sl) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{ind}, '{self._sql_format(self._name)}', " +
|
f"{ind}, '{self._db_format(self._name)}', " +
|
||||||
f"{self.x}, {self.y}, {self.z}, " +
|
f"{self.x}, {self.y}, {self.z}, " +
|
||||||
f"{profile.id}, {sl}" +
|
f"{profile.id}, {sl}" +
|
||||||
")"
|
")"
|
||||||
@@ -134,7 +128,6 @@ class PointXYZ(Point, SQLSubModel):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_data(cls, header, data):
|
def from_data(cls, header, data):
|
||||||
point = None
|
point = None
|
||||||
@@ -157,7 +150,6 @@ class PointXYZ(Point, SQLSubModel):
|
|||||||
|
|
||||||
return point
|
return point
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"({self._x}, {self._y}, {self._z}, {self._name})"
|
return f"({self._x}, {self._y}, {self._z}, {self._name})"
|
||||||
|
|
||||||
|
|||||||
@@ -25,14 +25,15 @@ from Model.Except import NotImplementedMethodeError
|
|||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class Profile(object):
|
class Profile(object):
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
|
|
||||||
def __init__(self, id:int = -1, num:int = 0,
|
def __init__(self, id: int = -1, num: int = 0,
|
||||||
kp:float = 0.0, name:str = "",
|
kp: float = 0.0, name: str = "",
|
||||||
code1:int = 0, code2:int = 0,
|
code1: int = 0, code2: int = 0,
|
||||||
_type:str = "", reach = None,
|
_type: str = "", reach=None,
|
||||||
status = None):
|
status=None):
|
||||||
super(Profile, self).__init__()
|
super(Profile, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -56,16 +57,35 @@ class Profile(object):
|
|||||||
|
|
||||||
self._profile_type = _type
|
self._profile_type = _type
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self.points)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def number_points(self):
|
def number_points(self):
|
||||||
return len(self._points)
|
return len(self.points)
|
||||||
|
|
||||||
|
def _get_points_list(self):
|
||||||
|
# Points list generator is type (int, Point) with the first
|
||||||
|
# element the index of the Point in list
|
||||||
|
return list(
|
||||||
|
map(
|
||||||
|
lambda p: p[1],
|
||||||
|
sorted(
|
||||||
|
self._points,
|
||||||
|
key=lambda p: p[0]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def points(self):
|
def points(self):
|
||||||
return self._points.copy()
|
if not isinstance(self._points, list):
|
||||||
|
self._points = self._get_points_list()
|
||||||
|
|
||||||
|
return self._points
|
||||||
|
|
||||||
def point(self, index):
|
def point(self, index):
|
||||||
return self._points[index]
|
return self.points[index]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def reach(self):
|
def reach(self):
|
||||||
@@ -112,7 +132,7 @@ class Profile(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def nb_points(self):
|
def nb_points(self):
|
||||||
return len(self._points)
|
return len(self.points)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def kp(self):
|
def kp(self):
|
||||||
@@ -166,9 +186,9 @@ class Profile(object):
|
|||||||
self._profile_type = value
|
self._profile_type = value
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def point(self, i:int):
|
def point(self, i: int):
|
||||||
if i < len(self._points):
|
if i < len(self.points):
|
||||||
return self._points[i]
|
return self.points[i]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -178,11 +198,10 @@ class Profile(object):
|
|||||||
Returns:
|
Returns:
|
||||||
The list of named point
|
The list of named point
|
||||||
"""
|
"""
|
||||||
return [point for point in self._points
|
return [point for point in self.points
|
||||||
if point.point_is_named()]
|
if point.point_is_named()]
|
||||||
|
|
||||||
|
def insert_point(self, index: int, point: Point):
|
||||||
def insert_point(self, index: int, point:Point):
|
|
||||||
"""Insert point at index.
|
"""Insert point at index.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -192,10 +211,9 @@ class Profile(object):
|
|||||||
Returns:
|
Returns:
|
||||||
Nothing.
|
Nothing.
|
||||||
"""
|
"""
|
||||||
self._points.insert(index, point)
|
self.points.insert(index, point)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
|
|
||||||
def delete(self, indexes: int):
|
def delete(self, indexes: int):
|
||||||
"""Delete points at index
|
"""Delete points at index
|
||||||
|
|
||||||
@@ -215,7 +233,7 @@ class Profile(object):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self._points = list(
|
self.points = list(
|
||||||
filter(
|
filter(
|
||||||
lambda p: p not in points,
|
lambda p: p not in points,
|
||||||
self.points
|
self.points
|
||||||
@@ -232,7 +250,7 @@ class Profile(object):
|
|||||||
Returns:
|
Returns:
|
||||||
Nothing.
|
Nothing.
|
||||||
"""
|
"""
|
||||||
self._points = list(
|
self.points = list(
|
||||||
filter(
|
filter(
|
||||||
lambda p: p not in points,
|
lambda p: p not in points,
|
||||||
self.points
|
self.points
|
||||||
@@ -243,10 +261,10 @@ class Profile(object):
|
|||||||
# Move
|
# Move
|
||||||
|
|
||||||
def move_up_point(self, index: int):
|
def move_up_point(self, index: int):
|
||||||
if index < len(self._points):
|
if index < len(self.points):
|
||||||
next = index - 1
|
next = index - 1
|
||||||
|
|
||||||
p = self._points
|
p = self.points
|
||||||
p[index], p[next] = p[next], p[index]
|
p[index], p[next] = p[next], p[index]
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
@@ -254,7 +272,7 @@ class Profile(object):
|
|||||||
if index >= 0:
|
if index >= 0:
|
||||||
prev = index + 1
|
prev = index + 1
|
||||||
|
|
||||||
p = self._points
|
p = self.points
|
||||||
p[index], p[prev] = p[prev], p[index]
|
p[index], p[prev] = p[prev], p[index]
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
@@ -262,14 +280,14 @@ class Profile(object):
|
|||||||
|
|
||||||
@timer
|
@timer
|
||||||
def sort(self, column, is_reversed: bool = False):
|
def sort(self, column, is_reversed: bool = False):
|
||||||
predicate = lambda p: p.x
|
def predicate(p): return p.x
|
||||||
if column == 'y':
|
if column == 'y':
|
||||||
predicate = lambda p: p.y
|
def predicate(p): return p.y
|
||||||
elif column == 'z':
|
elif column == 'z':
|
||||||
predicate = lambda p: p.z
|
def predicate(p): return p.z
|
||||||
|
|
||||||
self._points = sorted(
|
self.points = sorted(
|
||||||
self._points,
|
self.points,
|
||||||
key=predicate,
|
key=predicate,
|
||||||
reverse=is_reversed
|
reverse=is_reversed
|
||||||
)
|
)
|
||||||
@@ -277,10 +295,10 @@ class Profile(object):
|
|||||||
|
|
||||||
@timer
|
@timer
|
||||||
def sort_with_indexes(self, indexes: list):
|
def sort_with_indexes(self, indexes: list):
|
||||||
if len(self._points) != len(indexes):
|
if len(self.points) != len(indexes):
|
||||||
logger.critical("Indexes list do not correspond to point list")
|
logger.critical("Indexes list do not correspond to point list")
|
||||||
|
|
||||||
self._points = list(
|
self.points = list(
|
||||||
map(
|
map(
|
||||||
lambda x: x[1],
|
lambda x: x[1],
|
||||||
sorted(
|
sorted(
|
||||||
@@ -327,3 +345,9 @@ class Profile(object):
|
|||||||
# Abstract method, must be implemented for in non abstract class
|
# Abstract method, must be implemented for in non abstract class
|
||||||
def get_station(self):
|
def get_station(self):
|
||||||
raise NotImplementedMethodeError(self, self.get_station)
|
raise NotImplementedMethodeError(self, self.get_station)
|
||||||
|
|
||||||
|
# Computation method
|
||||||
|
|
||||||
|
# Abstract method for width approximation
|
||||||
|
def width_approximation(self):
|
||||||
|
raise NotImplementedMethodeError(self, self.width_approximation)
|
||||||
@@ -16,17 +16,21 @@
|
|||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from tools import timer
|
from tools import timer
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Except import ClipboardFormatError
|
from Model.Except import ClipboardFormatError
|
||||||
from Model.Geometry.Profile import Profile
|
from Model.Geometry.Profile import Profile
|
||||||
from Model.Geometry.PointXYZ import PointXYZ
|
from Model.Geometry.PointXYZ import PointXYZ
|
||||||
from Model.Geometry.Vector_1d import Vector1d
|
from Model.Geometry.Vector_1d import Vector1d
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class ProfileXYZ(Profile, SQLSubModel):
|
class ProfileXYZ(Profile, SQLSubModel):
|
||||||
_sub_classes = [
|
_sub_classes = [
|
||||||
PointXYZ,
|
PointXYZ,
|
||||||
@@ -36,11 +40,11 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
id: int = -1,
|
id: int = -1,
|
||||||
name: str = "",
|
name: str = "",
|
||||||
kp: float = 0.,
|
kp: float = 0.,
|
||||||
reach = None,
|
reach=None,
|
||||||
num = 0,
|
num=0,
|
||||||
nb_point: int = 0,
|
nb_point: int = 0,
|
||||||
code1: int = 0, code2: int = 0,
|
code1: int = 0, code2: int = 0,
|
||||||
status = None):
|
status=None):
|
||||||
"""ProfileXYZ constructor
|
"""ProfileXYZ constructor
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -54,18 +58,18 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
Nothing.
|
Nothing.
|
||||||
"""
|
"""
|
||||||
super(ProfileXYZ, self).__init__(
|
super(ProfileXYZ, self).__init__(
|
||||||
id = id,
|
id=id,
|
||||||
num = num,
|
num=num,
|
||||||
name = name,
|
name=name,
|
||||||
kp = kp,
|
kp=kp,
|
||||||
code1 = code1, code2 = code2,
|
code1=code1, code2=code2,
|
||||||
_type = "XYZ",
|
_type="XYZ",
|
||||||
reach = reach,
|
reach=reach,
|
||||||
status = status,
|
status=status,
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE geometry_profileXYZ(
|
CREATE TABLE geometry_profileXYZ(
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
@@ -85,7 +89,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
if major == minor == "0":
|
if major == minor == "0":
|
||||||
if int(release) < 2:
|
if int(release) < 2:
|
||||||
@@ -100,7 +104,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
return cls._update_submodel(execute, version)
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
profiles = []
|
profiles = []
|
||||||
status = data["status"]
|
status = data["status"]
|
||||||
reach = data["reach"]
|
reach = data["reach"]
|
||||||
@@ -108,7 +112,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
table = execute(
|
table = execute(
|
||||||
"SELECT id, ind, name, kp, num, code1, code2, sl " +
|
"SELECT id, ind, name, kp, num, code1, code2, sl " +
|
||||||
"FROM geometry_profileXYZ " +
|
"FROM geometry_profileXYZ " +
|
||||||
f"WHERE reach = {reach}"
|
f"WHERE reach = {reach.id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
for _ in table:
|
for _ in table:
|
||||||
@@ -125,14 +129,14 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
sl = row[7]
|
sl = row[7]
|
||||||
|
|
||||||
new = cls(
|
new = cls(
|
||||||
id=id, num = num,
|
id=id, num=num,
|
||||||
name = name, kp = kp,
|
name=name, kp=kp,
|
||||||
code1 = code1, code2 = code2,
|
code1=code1, code2=code2,
|
||||||
reach = data["parent"],
|
reach=data["parent"],
|
||||||
status = status
|
status=status
|
||||||
)
|
)
|
||||||
|
|
||||||
if sl == -1 or sl == None:
|
if sl == -1 or sl is None:
|
||||||
new._sl = None
|
new._sl = None
|
||||||
else:
|
else:
|
||||||
new._sl = next(
|
new._sl = next(
|
||||||
@@ -143,13 +147,15 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
data["profile"] = new
|
data["profile"] = new
|
||||||
new._points = PointXYZ._sql_load(execute, data)
|
new._points = PointXYZ._db_load(execute, data.copy())
|
||||||
|
|
||||||
profiles[ind] = new
|
yield ind, new
|
||||||
|
|
||||||
return profiles
|
# profiles[ind] = new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
# return profiles
|
||||||
|
|
||||||
|
def _db_save(self, execute, data=None):
|
||||||
ok = True
|
ok = True
|
||||||
ind = data["ind"]
|
ind = data["ind"]
|
||||||
|
|
||||||
@@ -157,22 +163,25 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT OR REPLACE INTO " +
|
"INSERT OR REPLACE INTO " +
|
||||||
"geometry_profileXYZ(id, ind, name, reach, kp, num, code1, code2, sl) "+
|
"geometry_profileXYZ(id, ind, name, reach, " +
|
||||||
|
"kp, num, code1, code2, sl) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {ind}, '{self._sql_format(self._name)}', " +
|
f"{self.id}, {ind}, '{self._db_format(self._name)}', " +
|
||||||
f"{self.reach.id}, {self.kp}, {self.num}, " +
|
f"{self.reach.id}, {self.kp}, {self.num}, " +
|
||||||
f"{self.code1}, {self.code1}, {sl}" +
|
f"{self.code1}, {self.code1}, {sl}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
|
|
||||||
|
points = self.points
|
||||||
|
|
||||||
data["profile"] = self
|
data["profile"] = self
|
||||||
execute(f"DELETE FROM geometry_pointXYZ WHERE profile = {self.id}")
|
execute(f"DELETE FROM geometry_pointXYZ WHERE profile = {self.id}")
|
||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
for point in self._points:
|
for point in points:
|
||||||
data["ind"] = ind
|
data["ind"] = ind
|
||||||
ok &= point._sql_save(execute, data)
|
ok &= point._db_save(execute, data)
|
||||||
ind += 1
|
ind += 1
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
@@ -220,18 +229,17 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
|
|
||||||
return point
|
return point
|
||||||
|
|
||||||
|
|
||||||
def x(self):
|
def x(self):
|
||||||
return [point.x for point in self._points]
|
return [point.x for point in self.points]
|
||||||
|
|
||||||
def y(self):
|
def y(self):
|
||||||
return [point.y for point in self._points]
|
return [point.y for point in self.points]
|
||||||
|
|
||||||
def z(self):
|
def z(self):
|
||||||
return [point.z for point in self._points]
|
return [point.z for point in self.points]
|
||||||
|
|
||||||
def names(self):
|
def names(self):
|
||||||
return [point.name for point in self._points]
|
return [point.name for point in self.points]
|
||||||
|
|
||||||
def x_max(self):
|
def x_max(self):
|
||||||
return max(self.filter_isnan(self.x()))
|
return max(self.filter_isnan(self.x()))
|
||||||
@@ -262,7 +270,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
"""
|
"""
|
||||||
for point in list_points:
|
for point in list_points:
|
||||||
pt = PointXYZ(*point, profile=self, status=self._status)
|
pt = PointXYZ(*point, profile=self, status=self._status)
|
||||||
self._points.append(pt)
|
self.points.append(pt)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def get_point_i(self, index: int) -> PointXYZ:
|
def get_point_i(self, index: int) -> PointXYZ:
|
||||||
@@ -275,10 +283,31 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
The point.
|
The point.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return self._points[index]
|
return self.points[index]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise IndexError(f"Invalid point index: {index}")
|
raise IndexError(f"Invalid point index: {index}")
|
||||||
|
|
||||||
|
def get_point_by_name(self, name: str) -> PointXYZ:
|
||||||
|
"""Get point by name.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: Point name.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The point.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
n_name = name.lower().strip()
|
||||||
|
return next(
|
||||||
|
filter(
|
||||||
|
lambda p: p.name.lower().strip() == n_name,
|
||||||
|
self.points
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f"{e}")
|
||||||
|
raise IndexError(f"Invalid point name: {name}")
|
||||||
|
|
||||||
def add(self):
|
def add(self):
|
||||||
"""Add a new PointXYZ to profile.
|
"""Add a new PointXYZ to profile.
|
||||||
|
|
||||||
@@ -286,7 +315,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
Nothing.
|
Nothing.
|
||||||
"""
|
"""
|
||||||
point_xyz = PointXYZ(0., 0., 0., profile=self, status=self._status)
|
point_xyz = PointXYZ(0., 0., 0., profile=self, status=self._status)
|
||||||
self._points.append(point_xyz)
|
self.points.append(point_xyz)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def insert(self, index: int):
|
def insert(self, index: int):
|
||||||
@@ -299,7 +328,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
The new point.
|
The new point.
|
||||||
"""
|
"""
|
||||||
point = PointXYZ(0., 0., 0., profile=self, status=self._status)
|
point = PointXYZ(0., 0., 0., profile=self, status=self._status)
|
||||||
self._points.insert(index, point)
|
self.points.insert(index, point)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return point
|
return point
|
||||||
|
|
||||||
@@ -315,9 +344,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
return [x for x in lst if not np.isnan(x)]
|
return [x for x in lst if not np.isnan(x)]
|
||||||
|
|
||||||
def _first_point_not_nan(self):
|
def _first_point_not_nan(self):
|
||||||
first_point = self._points[0]
|
first_point = self.points[0]
|
||||||
|
|
||||||
for point in self._points:
|
for point in self.points:
|
||||||
if not point.is_nan():
|
if not point.is_nan():
|
||||||
first_point = point
|
first_point = point
|
||||||
break
|
break
|
||||||
@@ -325,9 +354,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
return first_point
|
return first_point
|
||||||
|
|
||||||
def _last_point_not_nan(self):
|
def _last_point_not_nan(self):
|
||||||
last_point = self._points[-1]
|
last_point = self.points[-1]
|
||||||
|
|
||||||
for point in self._points[::-1]:
|
for point in self.points[::-1]:
|
||||||
if not point.is_nan():
|
if not point.is_nan():
|
||||||
last_point = point
|
last_point = point
|
||||||
break
|
break
|
||||||
@@ -354,13 +383,13 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
first_point_not_nan = self._first_point_not_nan()
|
first_point_not_nan = self._first_point_not_nan()
|
||||||
last_point_not_nan = self._last_point_not_nan()
|
last_point_not_nan = self._last_point_not_nan()
|
||||||
|
|
||||||
for index, point in enumerate(self._points):
|
for index, point in enumerate(self.points):
|
||||||
if point.point_is_named():
|
if point.point_is_named():
|
||||||
index_first_named_point = index
|
index_first_named_point = index
|
||||||
first_named_point = point
|
first_named_point = point
|
||||||
break
|
break
|
||||||
|
|
||||||
for point in reversed(self._points):
|
for point in reversed(self.points):
|
||||||
if point.point_is_named():
|
if point.point_is_named():
|
||||||
last_named_point = point
|
last_named_point = point
|
||||||
break
|
break
|
||||||
@@ -369,32 +398,32 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
constant = 0.0
|
constant = 0.0
|
||||||
|
|
||||||
if (first_named_point is not None and
|
if (first_named_point is not None and
|
||||||
last_named_point is not None):
|
last_named_point is not None):
|
||||||
if (first_named_point != last_named_point and
|
if (first_named_point != last_named_point and
|
||||||
first_named_point.x != last_named_point.x):
|
first_named_point.x != last_named_point.x):
|
||||||
vector = Vector1d(first_named_point, last_named_point)
|
vector = Vector1d(first_named_point, last_named_point)
|
||||||
normalized_direction_vec = vector.normalized_direction_vector()
|
norm_dir_vec = vector.normalized_direction_vector()
|
||||||
else:
|
else:
|
||||||
vector = Vector1d(first_point_not_nan, last_point_not_nan)
|
vector = Vector1d(first_point_not_nan, last_point_not_nan)
|
||||||
normalized_direction_vec = vector.normalized_direction_vector()
|
norm_dir_vec = vector.normalized_direction_vector()
|
||||||
|
|
||||||
for point in self._points:
|
for point in self.points:
|
||||||
xi = point.x - first_named_point.x
|
xi = point.x - first_named_point.x
|
||||||
yi = point.y - first_named_point.y
|
yi = point.y - first_named_point.y
|
||||||
station_i = (normalized_direction_vec[0] * xi +
|
station_i = (norm_dir_vec[0] * xi +
|
||||||
normalized_direction_vec[1] * yi)
|
norm_dir_vec[1] * yi)
|
||||||
station.append(station_i)
|
station.append(station_i)
|
||||||
|
|
||||||
constant = station[index_first_named_point]
|
constant = station[index_first_named_point]
|
||||||
elif first_named_point is None:
|
elif first_named_point is None:
|
||||||
vector = Vector1d(first_point_not_nan, last_point_not_nan)
|
vector = Vector1d(first_point_not_nan, last_point_not_nan)
|
||||||
normalized_direction_vec = vector.normalized_direction_vector()
|
norm_dir_vec = vector.normalized_direction_vector()
|
||||||
|
|
||||||
for point in self._points:
|
for point in self.points:
|
||||||
xi = point.x - first_point_not_nan.x
|
xi = point.x - first_point_not_nan.x
|
||||||
yi = point.y - first_point_not_nan.y
|
yi = point.y - first_point_not_nan.y
|
||||||
station_i = (normalized_direction_vec[0] * xi +
|
station_i = (norm_dir_vec[0] * xi +
|
||||||
normalized_direction_vec[1] * yi)
|
norm_dir_vec[1] * yi)
|
||||||
station.append(station_i)
|
station.append(station_i)
|
||||||
|
|
||||||
z_min = self.z_min()
|
z_min = self.z_min()
|
||||||
@@ -407,3 +436,9 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||||||
constant = station[index_profile_z_min[0]]
|
constant = station[index_profile_z_min[0]]
|
||||||
|
|
||||||
return list(map(lambda s: s - constant, station))
|
return list(map(lambda s: s - constant, station))
|
||||||
|
|
||||||
|
def width_approximation(self):
|
||||||
|
rg = self.get_point_by_name("rg")
|
||||||
|
rd = self.get_point_by_name("rd")
|
||||||
|
|
||||||
|
return abs(rg.dist(rd))
|
||||||
@@ -27,7 +27,7 @@ from functools import reduce
|
|||||||
|
|
||||||
from tools import flatten, timer, trace
|
from tools import flatten, timer, trace
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
|
||||||
from Model.Geometry.Profile import Profile
|
from Model.Geometry.Profile import Profile
|
||||||
from Model.Geometry.ProfileXYZ import ProfileXYZ
|
from Model.Geometry.ProfileXYZ import ProfileXYZ
|
||||||
@@ -36,13 +36,14 @@ from Model.Except import FileFormatError, exception_message_box
|
|||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class Reach(SQLSubModel):
|
class Reach(SQLSubModel):
|
||||||
_sub_classes = [
|
_sub_classes = [
|
||||||
ProfileXYZ,
|
ProfileXYZ,
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, status=None, parent=None):
|
def __init__(self, status=None, parent=None):
|
||||||
self.id = parent.id
|
self.id = parent.id if parent is not None else 0
|
||||||
self._status = status
|
self._status = status
|
||||||
self._parent = parent
|
self._parent = parent
|
||||||
self._profiles: List[Profile] = []
|
self._profiles: List[Profile] = []
|
||||||
@@ -51,36 +52,37 @@ class Reach(SQLSubModel):
|
|||||||
self._guidelines = {}
|
self._guidelines = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
return cls._update_submodel(execute, version)
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = cls(status = data["status"], parent = data["parent"])
|
new = cls(status=data["status"], parent=data["parent"])
|
||||||
|
|
||||||
new._profiles = ProfileXYZ._sql_load(
|
new._profiles = ProfileXYZ._db_load(
|
||||||
execute,
|
execute,
|
||||||
data = data
|
data=data
|
||||||
)
|
)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
|
profiles = self.profiles
|
||||||
|
|
||||||
# Delete old data
|
# Delete old data
|
||||||
execute(f"DELETE FROM geometry_profileXYZ WHERE reach = {self.id}")
|
execute(f"DELETE FROM geometry_profileXYZ WHERE reach = {self.id}")
|
||||||
# execute(f"DELETE FROM geometry_pointXYZ")
|
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
for profile in self._profiles:
|
for profile in profiles:
|
||||||
data["ind"] = ind
|
data["ind"] = ind
|
||||||
profile._sql_save(execute, data)
|
profile._db_save(execute, data)
|
||||||
ind += 1
|
ind += 1
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@@ -94,26 +96,53 @@ class Reach(SQLSubModel):
|
|||||||
Returns:
|
Returns:
|
||||||
The profile at index i
|
The profile at index i
|
||||||
"""
|
"""
|
||||||
if i < len(self._profiles):
|
if i < len(self.profiles):
|
||||||
return self._profiles[i]
|
return self.profiles[i]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
if self._parent == None:
|
if self._parent is None:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
return self._parent.name
|
return self._parent.name
|
||||||
|
|
||||||
|
def _get_profiles_list(self):
|
||||||
|
# Profiles list generator is type (int, Point) with the first
|
||||||
|
# element the index of the Point in list
|
||||||
|
logger.info(f"Load profiles from reach {self.name}")
|
||||||
|
return list(
|
||||||
|
map(
|
||||||
|
lambda p: p[1],
|
||||||
|
sorted(
|
||||||
|
self._profiles,
|
||||||
|
key=lambda p: p[0]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
if not isinstance(self._profiles, list):
|
||||||
|
self._profiles = self._get_profiles_list()
|
||||||
|
|
||||||
|
return len(self._profiles)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def profiles(self):
|
def profiles(self):
|
||||||
return self._profiles.copy()
|
if not isinstance(self._profiles, list):
|
||||||
|
self._profiles = self._get_profiles_list()
|
||||||
|
|
||||||
|
return self._profiles
|
||||||
|
|
||||||
|
@profiles.setter
|
||||||
|
def profiles(self, profiles):
|
||||||
|
self._profiles = profiles
|
||||||
|
|
||||||
def get_profiles_from_kp(self, kp):
|
def get_profiles_from_kp(self, kp):
|
||||||
return list(
|
return list(
|
||||||
filter(
|
filter(
|
||||||
lambda p: p.kp == kp, self._profiles
|
lambda p: p.kp == kp, self.profiles
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -123,14 +152,14 @@ class Reach(SQLSubModel):
|
|||||||
Returns:
|
Returns:
|
||||||
Number of profiles
|
Number of profiles
|
||||||
"""
|
"""
|
||||||
return len(self._profiles)
|
return len(self.profiles)
|
||||||
|
|
||||||
def get_geometry(self) -> List[Profile]:
|
def get_geometry(self) -> List[Profile]:
|
||||||
"""
|
"""
|
||||||
Returns:
|
Returns:
|
||||||
The profiles list.
|
The profiles list.
|
||||||
"""
|
"""
|
||||||
return self._profiles
|
return self.profiles
|
||||||
|
|
||||||
def _update_profile_numbers(self):
|
def _update_profile_numbers(self):
|
||||||
"""Update profiles index
|
"""Update profiles index
|
||||||
@@ -152,7 +181,7 @@ class Reach(SQLSubModel):
|
|||||||
"""
|
"""
|
||||||
profile = ProfileXYZ(reach=self, status=self._status)
|
profile = ProfileXYZ(reach=self, status=self._status)
|
||||||
|
|
||||||
self._profiles.insert(index, profile)
|
self.profiles.insert(index, profile)
|
||||||
self._update_profile_numbers()
|
self._update_profile_numbers()
|
||||||
|
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
@@ -168,11 +197,10 @@ class Reach(SQLSubModel):
|
|||||||
Returns:
|
Returns:
|
||||||
Nothing.
|
Nothing.
|
||||||
"""
|
"""
|
||||||
self._profiles.insert(index, profile)
|
self.profiles.insert(index, profile)
|
||||||
self._update_profile_numbers()
|
self._update_profile_numbers()
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
|
|
||||||
def delete(self, indexes):
|
def delete(self, indexes):
|
||||||
"""Delete some elements in profile list
|
"""Delete some elements in profile list
|
||||||
|
|
||||||
@@ -219,12 +247,11 @@ class Reach(SQLSubModel):
|
|||||||
self._update_profile_numbers()
|
self._update_profile_numbers()
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
|
|
||||||
def move_up_profile(self, index: int):
|
def move_up_profile(self, index: int):
|
||||||
if index < len(self.profiles):
|
if index < len(self.profiles):
|
||||||
next = index - 1
|
next = index - 1
|
||||||
|
|
||||||
p = self._profiles
|
p = self.profiles
|
||||||
p[index], p[next] = p[next], p[index]
|
p[index], p[next] = p[next], p[index]
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
@@ -232,7 +259,7 @@ class Reach(SQLSubModel):
|
|||||||
if index >= 0:
|
if index >= 0:
|
||||||
prev = index + 1
|
prev = index + 1
|
||||||
|
|
||||||
p = self._profiles
|
p = self.profiles
|
||||||
p[index], p[prev] = p[prev], p[index]
|
p[index], p[prev] = p[prev], p[index]
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
@@ -275,7 +302,6 @@ class Reach(SQLSubModel):
|
|||||||
def get_kp_max(self):
|
def get_kp_max(self):
|
||||||
return max(self.get_kp())
|
return max(self.get_kp())
|
||||||
|
|
||||||
|
|
||||||
# Sediment Layers
|
# Sediment Layers
|
||||||
|
|
||||||
def get_sl(self):
|
def get_sl(self):
|
||||||
@@ -324,12 +350,12 @@ class Reach(SQLSubModel):
|
|||||||
for guide in guide_set:
|
for guide in guide_set:
|
||||||
self._guidelines[guide] = flatten(
|
self._guidelines[guide] = flatten(
|
||||||
map(
|
map(
|
||||||
lambda l: list(
|
lambda lst: list(
|
||||||
# Filter point with name (we assume we have
|
# Filter point with name (we assume we have
|
||||||
# only one point by profile)
|
# only one point by profile)
|
||||||
filter(
|
filter(
|
||||||
lambda p: p.name == guide,
|
lambda p: p.name == guide,
|
||||||
l
|
lst
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
named_points
|
named_points
|
||||||
@@ -344,7 +370,7 @@ class Reach(SQLSubModel):
|
|||||||
Tuple of complete and incomplete guidelines name.
|
Tuple of complete and incomplete guidelines name.
|
||||||
"""
|
"""
|
||||||
# Get all point contains into a guideline
|
# Get all point contains into a guideline
|
||||||
named_points = [profile.named_points() for profile in self._profiles]
|
named_points = [profile.named_points() for profile in self.profiles]
|
||||||
points_name = list(
|
points_name = list(
|
||||||
map(
|
map(
|
||||||
lambda lst: list(map(lambda p: p.name, lst)),
|
lambda lst: list(map(lambda p: p.name, lst)),
|
||||||
@@ -364,7 +390,9 @@ class Reach(SQLSubModel):
|
|||||||
reduce(
|
reduce(
|
||||||
lambda acc, h: acc + h,
|
lambda acc, h: acc + h,
|
||||||
map(
|
map(
|
||||||
lambda l: list(set(l).symmetric_difference(guide_set)),
|
lambda lst: list(
|
||||||
|
set(lst).symmetric_difference(guide_set)
|
||||||
|
),
|
||||||
points_name
|
points_name
|
||||||
),
|
),
|
||||||
[]
|
[]
|
||||||
@@ -414,13 +442,12 @@ class Reach(SQLSubModel):
|
|||||||
def get_guidelines_z(self):
|
def get_guidelines_z(self):
|
||||||
return self._map_guidelines_points(lambda p: p.z)
|
return self._map_guidelines_points(lambda p: p.z)
|
||||||
|
|
||||||
|
|
||||||
# Sort
|
# Sort
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def sort(self, is_reversed: bool = False):
|
def sort(self, is_reversed: bool = False):
|
||||||
self._profiles = sorted(
|
self.profiles = sorted(
|
||||||
self._profiles,
|
self.profiles,
|
||||||
key=lambda profile: profile.kp,
|
key=lambda profile: profile.kp,
|
||||||
reverse=is_reversed
|
reverse=is_reversed
|
||||||
)
|
)
|
||||||
@@ -428,10 +455,10 @@ class Reach(SQLSubModel):
|
|||||||
|
|
||||||
@timer
|
@timer
|
||||||
def sort_with_indexes(self, indexes: list):
|
def sort_with_indexes(self, indexes: list):
|
||||||
if len(self._profiles) != len(indexes):
|
if len(self.profiles) != len(indexes):
|
||||||
logger.critical("Indexes list do not correspond to profile list")
|
logger.critical("Indexes list do not correspond to profile list")
|
||||||
|
|
||||||
self._profiles = list(
|
self.profiles = list(
|
||||||
map(
|
map(
|
||||||
lambda x: x[1],
|
lambda x: x[1],
|
||||||
sorted(
|
sorted(
|
||||||
@@ -449,7 +476,8 @@ class Reach(SQLSubModel):
|
|||||||
"""Import a geometry from file (.ST or .st)
|
"""Import a geometry from file (.ST or .st)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
file_path_name: The absolute path of geometry file (.ST or .st) to import.
|
file_path_name: The absolute path of geometry file (.ST or .st)
|
||||||
|
to import.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Nothing.
|
Nothing.
|
||||||
@@ -459,7 +487,8 @@ class Reach(SQLSubModel):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
list_profile, list_header = self.read_file_st(str(file_path_name))
|
list_profile, list_header = self.read_file_st(str(file_path_name))
|
||||||
profile_header = ["num", "code1", "code2", "nb_point", "kp", "name"]
|
profile_header = ["num", "code1",
|
||||||
|
"code2", "nb_point", "kp", "name"]
|
||||||
|
|
||||||
if list_profile and list_header:
|
if list_profile and list_header:
|
||||||
for ind, profile in enumerate(list_profile):
|
for ind, profile in enumerate(list_profile):
|
||||||
@@ -471,7 +500,7 @@ class Reach(SQLSubModel):
|
|||||||
**d, reach=self, status=self._status
|
**d, reach=self, status=self._status
|
||||||
)
|
)
|
||||||
prof.import_points(profile)
|
prof.import_points(profile)
|
||||||
self._profiles.append(prof)
|
self.profiles.append(prof)
|
||||||
self._update_profile_numbers()
|
self._update_profile_numbers()
|
||||||
|
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
@@ -535,8 +564,8 @@ class Reach(SQLSubModel):
|
|||||||
# TODO: Move this function to model reach
|
# TODO: Move this function to model reach
|
||||||
def export_reach(self, filename):
|
def export_reach(self, filename):
|
||||||
with open(f"{filename}", "w") as file_st:
|
with open(f"{filename}", "w") as file_st:
|
||||||
for index in range(len(self._profiles)):
|
for index in range(len(self.profiles)):
|
||||||
profile = self._profiles[index]
|
profile = self.profiles[index]
|
||||||
|
|
||||||
for v in profile.header:
|
for v in profile.header:
|
||||||
file_st.write(f"{v:>6}")
|
file_st.write(f"{v:>6}")
|
||||||
@@ -549,3 +578,103 @@ class Reach(SQLSubModel):
|
|||||||
|
|
||||||
file_st.write(" 999.9990 999.9990 999.9990")
|
file_st.write(" 999.9990 999.9990 999.9990")
|
||||||
file_st.write("\n")
|
file_st.write("\n")
|
||||||
|
|
||||||
|
def get_incline(self):
|
||||||
|
first = self.profile(0)
|
||||||
|
last = self.profile(len(self) - 1)
|
||||||
|
|
||||||
|
z_first = first.z_min()
|
||||||
|
kp_first = first.kp
|
||||||
|
|
||||||
|
z_last = last.z_min()
|
||||||
|
kp_last = last.kp
|
||||||
|
|
||||||
|
return (
|
||||||
|
(z_last - z_first)
|
||||||
|
/
|
||||||
|
(kp_last - kp_first)
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_incline_mean(self):
|
||||||
|
profiles = self.profiles
|
||||||
|
previous = profiles[0]
|
||||||
|
|
||||||
|
incline_acc = 0
|
||||||
|
|
||||||
|
for profile in profiles[1:]:
|
||||||
|
z_first = previous.z_min()
|
||||||
|
kp_first = previous.kp
|
||||||
|
|
||||||
|
z_last = profile.z_min()
|
||||||
|
kp_last = profile.kp
|
||||||
|
|
||||||
|
incline_acc += (
|
||||||
|
(z_last - z_first)
|
||||||
|
/
|
||||||
|
(kp_last - kp_first)
|
||||||
|
)
|
||||||
|
|
||||||
|
previous = profile
|
||||||
|
|
||||||
|
return (incline_acc / (len(profiles) - 1))
|
||||||
|
|
||||||
|
def get_incline_median(self):
|
||||||
|
profiles = self.profiles
|
||||||
|
previous = profiles[0]
|
||||||
|
|
||||||
|
incline_acc = []
|
||||||
|
|
||||||
|
for profile in profiles[1:]:
|
||||||
|
z_first = previous.z_min()
|
||||||
|
kp_first = previous.kp
|
||||||
|
|
||||||
|
z_last = profile.z_min()
|
||||||
|
kp_last = profile.kp
|
||||||
|
|
||||||
|
incline_acc += [
|
||||||
|
(z_last - z_first)
|
||||||
|
/
|
||||||
|
(kp_last - kp_first)
|
||||||
|
]
|
||||||
|
|
||||||
|
previous = profile
|
||||||
|
|
||||||
|
incline_acc.sort()
|
||||||
|
return incline_acc[round(len(profiles)/2)]
|
||||||
|
|
||||||
|
def get_incline_median_mean(self):
|
||||||
|
profiles = self.profiles
|
||||||
|
previous = profiles[0]
|
||||||
|
|
||||||
|
incline_acc = []
|
||||||
|
|
||||||
|
for profile in profiles[1:]:
|
||||||
|
z_first = previous.z_min()
|
||||||
|
kp_first = previous.kp
|
||||||
|
|
||||||
|
z_last = profile.z_min()
|
||||||
|
kp_last = profile.kp
|
||||||
|
|
||||||
|
incline_acc += [
|
||||||
|
(z_last - z_first)
|
||||||
|
/
|
||||||
|
(kp_last - kp_first)
|
||||||
|
]
|
||||||
|
|
||||||
|
previous = profile
|
||||||
|
|
||||||
|
incline_acc.sort()
|
||||||
|
|
||||||
|
marge = round(len(incline_acc) * 0.1)
|
||||||
|
incline_set = incline_acc[marge:-marge]
|
||||||
|
|
||||||
|
logger.debug(f"+{incline_acc}")
|
||||||
|
logger.debug(f"-{incline_set}")
|
||||||
|
|
||||||
|
return (
|
||||||
|
reduce(
|
||||||
|
lambda acc, x: acc + x,
|
||||||
|
incline_set,
|
||||||
|
0.0
|
||||||
|
) / (len(incline_set))
|
||||||
|
)
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from Model.Geometry.PointXYZ import PointXYZ
|
from Model.Geometry.PointXYZ import PointXYZ
|
||||||
|
|
||||||
|
|
||||||
class Vector1d:
|
class Vector1d:
|
||||||
def __init__(self, a: PointXYZ, b: PointXYZ):
|
def __init__(self, a: PointXYZ, b: PointXYZ):
|
||||||
self.A = a
|
self.A = a
|
||||||
|
|||||||
@@ -16,18 +16,23 @@
|
|||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from copy import copy, deepcopy
|
from copy import copy, deepcopy
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class Data(SQLSubModel):
|
class Data(SQLSubModel):
|
||||||
def __init__(self, name:str = "",
|
def __init__(self, name: str = "",
|
||||||
comment:str = "", reach = None,
|
comment: str = "", reach=None,
|
||||||
kp:float = 0.0, discharge:float = 0.0,
|
kp: float = 0.0, discharge: float = 0.0,
|
||||||
height:float = 0.0,
|
height: float = 0.0,
|
||||||
status = None):
|
status=None):
|
||||||
super(Data, self).__init__()
|
super(Data, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -51,7 +56,7 @@ class Data(SQLSubModel):
|
|||||||
self._update_from_discharge()
|
self._update_from_discharge()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE initial_conditions(
|
CREATE TABLE initial_conditions(
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -69,11 +74,11 @@ class Data(SQLSubModel):
|
|||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
return cls._update_submodel(execute, version)
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
id = data["reach"].id
|
id = data["reach"].id
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT ind, name, comment, kp, discharge, height " +
|
"SELECT ind, name, comment, kp, discharge, height " +
|
||||||
@@ -95,28 +100,29 @@ class Data(SQLSubModel):
|
|||||||
height = row[5]
|
height = row[5]
|
||||||
|
|
||||||
d = cls(
|
d = cls(
|
||||||
reach = data["reach"],
|
reach=data["reach"],
|
||||||
status = data["status"],
|
status=data["status"],
|
||||||
name = name,
|
name=name,
|
||||||
comment = comment,
|
comment=comment,
|
||||||
kp = kp,
|
kp=kp,
|
||||||
discharge = discharge,
|
discharge=discharge,
|
||||||
height = height,
|
height=height,
|
||||||
)
|
)
|
||||||
|
|
||||||
new[ind] = d
|
new[ind] = d
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
ind = data["ind"]
|
ind = data["ind"]
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"initial_conditions(ind, name, comment, kp, discharge, height, reach) " +
|
"initial_conditions(ind, name, comment, kp, " +
|
||||||
|
"discharge, height, reach) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{ind}, '{self._sql_format(self.name)}', " +
|
f"{ind}, '{self._db_format(self.name)}', " +
|
||||||
f"'{self._sql_format(self._comment)}', " +
|
f"'{self._db_format(self._comment)}', " +
|
||||||
f"{self._kp}, {self._discharge}, {self._height}, " +
|
f"{self._kp}, {self._discharge}, {self._height}, " +
|
||||||
f"{self._reach.id}" +
|
f"{self._reach.id}" +
|
||||||
")"
|
")"
|
||||||
@@ -124,16 +130,15 @@ class Data(SQLSubModel):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
new = Data(
|
new = Data(
|
||||||
name = self.name,
|
name=self.name,
|
||||||
comment = self._comment,
|
comment=self._comment,
|
||||||
kp = self._kp,
|
kp=self._kp,
|
||||||
discharge = self._discharge,
|
discharge=self._discharge,
|
||||||
height = self._height,
|
height=self._height,
|
||||||
reach = self._reach,
|
reach=self._reach,
|
||||||
status = self._status,
|
status=self._status,
|
||||||
)
|
)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
@@ -173,7 +178,7 @@ class Data(SQLSubModel):
|
|||||||
|
|
||||||
def _update_from_kp(self):
|
def _update_from_kp(self):
|
||||||
min = self._update_get_min()
|
min = self._update_get_min()
|
||||||
self._elevation = min - self._height
|
self._elevation = min + self._height
|
||||||
|
|
||||||
def _update_from_elevation(self):
|
def _update_from_elevation(self):
|
||||||
min = self._update_get_min()
|
min = self._update_get_min()
|
||||||
@@ -216,7 +221,7 @@ class InitialConditions(SQLSubModel):
|
|||||||
Data
|
Data
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, reach = None, status = None):
|
def __init__(self, reach=None, status=None):
|
||||||
super(InitialConditions, self).__init__()
|
super(InitialConditions, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -225,37 +230,35 @@ class InitialConditions(SQLSubModel):
|
|||||||
self._data = []
|
self._data = []
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
return cls._update_submodel(execute, version)
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = cls(
|
new = cls(
|
||||||
reach = data["reach"],
|
reach=data["reach"],
|
||||||
status = data["status"]
|
status=data["status"]
|
||||||
)
|
)
|
||||||
|
|
||||||
new._data = Data._sql_load(
|
new._data = Data._db_load(
|
||||||
execute,
|
execute,
|
||||||
data = data
|
data=data
|
||||||
)
|
)
|
||||||
|
|
||||||
if new._data is None:
|
if new._data is not None:
|
||||||
return None
|
yield new
|
||||||
|
|
||||||
return new
|
def _db_save(self, execute, data=None):
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
|
||||||
ok = True
|
ok = True
|
||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
for d in self._data:
|
for d in self._data:
|
||||||
data["ind"] = ind
|
data["ind"] = ind
|
||||||
ok &= d._sql_save(execute, data)
|
ok &= d._db_save(execute, data)
|
||||||
ind += 1
|
ind += 1
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
@@ -288,7 +291,7 @@ class InitialConditions(SQLSubModel):
|
|||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def new(self, index):
|
def new(self, index):
|
||||||
n = Data(reach = self._reach, status = self._status)
|
n = Data(reach=self._reach, status=self._status)
|
||||||
self._data.insert(index, n)
|
self._data.insert(index, n)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
@@ -321,7 +324,6 @@ class InitialConditions(SQLSubModel):
|
|||||||
self._data.sort(reverse=reverse, key=key)
|
self._data.sort(reverse=reverse, key=key)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
|
|
||||||
def _data_get(self, key):
|
def _data_get(self, key):
|
||||||
return list(
|
return list(
|
||||||
map(
|
map(
|
||||||
@@ -341,8 +343,8 @@ class InitialConditions(SQLSubModel):
|
|||||||
|
|
||||||
def _sort_by_z_and_kp(self, profiles):
|
def _sort_by_z_and_kp(self, profiles):
|
||||||
profiles.sort(
|
profiles.sort(
|
||||||
reverse = False,
|
reverse=False,
|
||||||
key = lambda p: p.kp
|
key=lambda p: p.kp
|
||||||
)
|
)
|
||||||
|
|
||||||
first_z = profiles[0].z()
|
first_z = profiles[0].z()
|
||||||
@@ -350,47 +352,89 @@ class InitialConditions(SQLSubModel):
|
|||||||
|
|
||||||
if first_z > last_z:
|
if first_z > last_z:
|
||||||
profiles.sort(
|
profiles.sort(
|
||||||
reverse = True,
|
reverse=True,
|
||||||
key = lambda p: p.kp
|
key=lambda p: p.kp
|
||||||
)
|
)
|
||||||
|
|
||||||
def generate_growing_constante_height(self, height:float):
|
def generate_growing_constante_height(self, height: float):
|
||||||
self._data = []
|
self._data = []
|
||||||
|
|
||||||
profiles = self._reach.reach.profiles
|
profiles = self._reach.reach.profiles.copy()
|
||||||
self._sort_by_z_and_kp(profiles)
|
self._sort_by_z_and_kp(profiles)
|
||||||
|
|
||||||
prev = None
|
incline = self._reach.reach.get_incline_median_mean()
|
||||||
for profile in profiles:
|
logger.debug(f"incline = {incline}")
|
||||||
new = Data(reach = self._reach, status = self._status)
|
|
||||||
new["kp"] = profile.kp
|
|
||||||
|
|
||||||
if prev is None:
|
previous_elevation = -99999.99
|
||||||
new["elevation"] = profile.z_min() + height
|
for profile in profiles:
|
||||||
else:
|
width = profile.width_approximation()
|
||||||
new["elevation"] = max(
|
strickler = 25
|
||||||
profile.z_min() + height,
|
discharge = (
|
||||||
prev["elevation"]
|
((width * 0.8)
|
||||||
)
|
* strickler
|
||||||
|
* (height ** (5/3))
|
||||||
|
* (abs(incline) ** (0.5)))
|
||||||
|
)
|
||||||
|
|
||||||
|
elevation= max(
|
||||||
|
profile.z_min() + height,
|
||||||
|
previous_elevation
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.debug(f"({profile.kp}):")
|
||||||
|
logger.debug(f" width = {width}")
|
||||||
|
logger.debug(f" strickler = {strickler}")
|
||||||
|
logger.debug(f" discharge = {discharge}")
|
||||||
|
|
||||||
|
new = Data(reach=self._reach, status=self._status)
|
||||||
|
new["kp"] = profile.kp
|
||||||
|
new["discharge"] = discharge
|
||||||
|
|
||||||
|
new["elevation"] = elevation
|
||||||
|
|
||||||
self._data.append(new)
|
self._data.append(new)
|
||||||
prev = new
|
previous_elevation = elevation
|
||||||
|
|
||||||
is_reverse = False
|
|
||||||
if profiles[0].kp > profiles[-1].kp:
|
|
||||||
is_reverse = True
|
|
||||||
|
|
||||||
self._data.sort(
|
def generate_discharge(self, discharge: float):
|
||||||
reverse = not is_reverse,
|
self._data = []
|
||||||
key = lambda d: d['kp']
|
|
||||||
|
self._generate_height_estimation_from_discharge(
|
||||||
|
discharge
|
||||||
)
|
)
|
||||||
|
|
||||||
def generate_discharge(self, discharge:float):
|
def _generate_height_estimation_from_discharge(self, discharge: float):
|
||||||
self._new = []
|
profiles = self._reach.reach.profiles.copy()
|
||||||
|
self._sort_by_z_and_kp(profiles)
|
||||||
|
|
||||||
for d in self._data:
|
previous_elevation = -99999.99
|
||||||
n = d.copy()
|
|
||||||
n['discharge'] = discharge
|
|
||||||
self._new.append(n)
|
|
||||||
|
|
||||||
self._data = self._new
|
incline = self._reach.reach.get_incline_median_mean()
|
||||||
|
logger.debug(f"incline = {incline}")
|
||||||
|
|
||||||
|
for profile in profiles:
|
||||||
|
width = profile.width_approximation()
|
||||||
|
strickler = 25
|
||||||
|
height = (
|
||||||
|
discharge
|
||||||
|
/
|
||||||
|
((width * 0.8) * strickler * (abs(incline) ** (0.5)))
|
||||||
|
) ** (0.6)
|
||||||
|
|
||||||
|
elevation= max(
|
||||||
|
profile.z_min() + height,
|
||||||
|
previous_elevation
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.debug(f"({profile.kp}):")
|
||||||
|
logger.debug(f" width = {width}")
|
||||||
|
logger.debug(f" strickler = {strickler}")
|
||||||
|
logger.debug(f" hieght = {height}")
|
||||||
|
|
||||||
|
new = Data(reach=self._reach, status=self._status)
|
||||||
|
new["kp"] = profile.kp
|
||||||
|
new["discharge"] = discharge
|
||||||
|
new["elevation"] = elevation
|
||||||
|
|
||||||
|
previous_elevation = elevation
|
||||||
|
self._data.append(new)
|
||||||
@@ -16,81 +16,74 @@
|
|||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import types
|
||||||
|
import logging
|
||||||
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDict import PamhyrModelDict
|
||||||
from Model.InitialConditions.InitialConditions import InitialConditions
|
from Model.InitialConditions.InitialConditions import InitialConditions
|
||||||
|
|
||||||
class InitialConditionsDict(SQLSubModel):
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class InitialConditionsDict(PamhyrModelDict):
|
||||||
_sub_classes = [
|
_sub_classes = [
|
||||||
InitialConditions,
|
InitialConditions,
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, status = None):
|
|
||||||
super(InitialConditionsDict, self).__init__()
|
|
||||||
|
|
||||||
self._status = status
|
|
||||||
|
|
||||||
self._reach = {}
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_load(cls, execute, data=None):
|
||||||
return cls._create_submodel(execute)
|
new = cls(status=data["status"])
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _sql_update(cls, execute, version):
|
|
||||||
return cls._update_submodel(execute, version)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _sql_load(cls, execute, data = None):
|
|
||||||
new = cls(status = data["status"])
|
|
||||||
|
|
||||||
for reach in data["edges"]:
|
for reach in data["edges"]:
|
||||||
data["reach"] = reach
|
data["reach"] = reach
|
||||||
|
|
||||||
ic = InitialConditions._sql_load(
|
ic = InitialConditions._db_load(
|
||||||
execute,
|
execute,
|
||||||
data = data
|
data=data
|
||||||
)
|
)
|
||||||
|
|
||||||
if ic is not None:
|
if ic is not None:
|
||||||
new._reach[reach] = ic
|
new._dict[reach] = ic
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
ok = True
|
ok = True
|
||||||
if data is None:
|
if data is None:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
execute("DELETE FROM initial_conditions")
|
ics = self._dict
|
||||||
|
for reach in ics:
|
||||||
for reach in self._reach:
|
|
||||||
data["reach"] = reach
|
data["reach"] = reach
|
||||||
ok &= self._reach[reach]._sql_save(execute, data)
|
v = self._dict[reach]
|
||||||
|
if isinstance(v, types.GeneratorType):
|
||||||
|
self._dict[reach] = list(v)[0]
|
||||||
|
|
||||||
|
execute(
|
||||||
|
"DELETE FROM initial_conditions " +
|
||||||
|
f"WHERE reach = '{reach.id}'"
|
||||||
|
)
|
||||||
|
|
||||||
|
ok &= self._dict[reach]._db_save(execute, data)
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
|
|
||||||
def __len__(self):
|
def get(self, key):
|
||||||
return len(self._reach)
|
if key in self._dict:
|
||||||
|
v = self._dict[key]
|
||||||
|
if isinstance(v, types.GeneratorType):
|
||||||
|
self._dict[key] = list(v)[0]
|
||||||
|
|
||||||
def is_defined(self, reach):
|
return self._dict[key]
|
||||||
return reach in self._reach
|
|
||||||
|
|
||||||
def get(self, reach):
|
new = self.new(key)
|
||||||
if reach in self._reach:
|
self.set(key, new)
|
||||||
return self._reach[reach]
|
|
||||||
|
|
||||||
new = self.new(reach)
|
|
||||||
self.set(reach, new)
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def set(self, reach, new):
|
|
||||||
self._reach[reach] = new
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def new(self, reach):
|
def new(self, reach):
|
||||||
new = InitialConditions(reach = reach, status = self._status)
|
new = InitialConditions(reach=reach, status=self._status)
|
||||||
self.set(reach, new)
|
self.set(reach, new)
|
||||||
return new
|
return new
|
||||||
@@ -20,16 +20,17 @@ import logging
|
|||||||
|
|
||||||
from tools import trace, timer, old_pamhyr_date_to_timestamp
|
from tools import trace, timer, old_pamhyr_date_to_timestamp
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class LateralContribution(SQLSubModel):
|
class LateralContribution(SQLSubModel):
|
||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
|
|
||||||
def __init__(self, id:int = -1, name:str = "", status = None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
super(LateralContribution, self).__init__()
|
super(LateralContribution, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -39,7 +40,6 @@ class LateralContribution(SQLSubModel):
|
|||||||
else:
|
else:
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
self._type = ""
|
self._type = ""
|
||||||
self._edge = None
|
self._edge = None
|
||||||
@@ -49,10 +49,11 @@ class LateralContribution(SQLSubModel):
|
|||||||
self._header = []
|
self._header = []
|
||||||
self._types = [float, float]
|
self._types = [float, float]
|
||||||
|
|
||||||
LateralContribution._id_cnt = max(LateralContribution._id_cnt + 1, self.id)
|
LateralContribution._id_cnt = max(
|
||||||
|
LateralContribution._id_cnt + 1, self.id)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE lateral_contribution(
|
CREATE TABLE lateral_contribution(
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
@@ -80,7 +81,7 @@ class LateralContribution(SQLSubModel):
|
|||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -99,7 +100,7 @@ class LateralContribution(SQLSubModel):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
tab = data["tab"]
|
tab = data["tab"]
|
||||||
|
|
||||||
@@ -112,9 +113,9 @@ class LateralContribution(SQLSubModel):
|
|||||||
t = row[2]
|
t = row[2]
|
||||||
ctor = cls._get_ctor_from_type(t)
|
ctor = cls._get_ctor_from_type(t)
|
||||||
lc = ctor(
|
lc = ctor(
|
||||||
id = row[0],
|
id=row[0],
|
||||||
name = row[1],
|
name=row[1],
|
||||||
status = data['status']
|
status=data['status']
|
||||||
)
|
)
|
||||||
lc.edge = None
|
lc.edge = None
|
||||||
if row[3] != -1:
|
if row[3] != -1:
|
||||||
@@ -141,7 +142,7 @@ class LateralContribution(SQLSubModel):
|
|||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
tab = data["tab"]
|
tab = data["tab"]
|
||||||
|
|
||||||
execute(f"DELETE FROM lateral_contribution WHERE id = {self.id}")
|
execute(f"DELETE FROM lateral_contribution WHERE id = {self.id}")
|
||||||
@@ -153,10 +154,11 @@ class LateralContribution(SQLSubModel):
|
|||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"lateral_contribution(id, name, type, tab, edge, begin_kp, end_kp) "+
|
"lateral_contribution(id, name, type, tab, " +
|
||||||
|
"edge, begin_kp, end_kp) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, '{self._sql_format(self._name)}', " +
|
f"{self.id}, '{self._db_format(self._name)}', " +
|
||||||
f"'{self._sql_format(self._type)}', '{tab}', {edge}, " +
|
f"'{self._db_format(self._type)}', '{tab}', {edge}, " +
|
||||||
f"{self._begin_kp}, {self._end_kp}" +
|
f"{self._begin_kp}, {self._end_kp}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
@@ -164,12 +166,12 @@ class LateralContribution(SQLSubModel):
|
|||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
for d in self._data:
|
for d in self._data:
|
||||||
data0 = self._sql_format(str(d[0]))
|
data0 = self._db_format(str(d[0]))
|
||||||
data1 = self._sql_format(str(d[1]))
|
data1 = self._db_format(str(d[1]))
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"lateral_contribution_data(ind, data0, data1, lc) "+
|
"lateral_contribution_data(ind, data0, data1, lc) " +
|
||||||
f"VALUES ({ind}, '{data0}', {data1}, {self.id})"
|
f"VALUES ({ind}, '{data0}', {data1}, {self.id})"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
@@ -186,8 +188,13 @@ class LateralContribution(SQLSubModel):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def time_convert(cls, data):
|
def time_convert(cls, data):
|
||||||
if type(data) == str and data.count(":") == 3:
|
if type(data) is str:
|
||||||
return old_pamhyr_date_to_timestamp(data)
|
if data.count(":") == 3:
|
||||||
|
return old_pamhyr_date_to_timestamp(data)
|
||||||
|
if data.count(":") == 2:
|
||||||
|
return old_pamhyr_date_to_timestamp("00:" + data)
|
||||||
|
if data.count(".") == 1:
|
||||||
|
return round(float(data))
|
||||||
|
|
||||||
return int(data)
|
return int(data)
|
||||||
|
|
||||||
@@ -282,7 +289,7 @@ class LateralContribution(SQLSubModel):
|
|||||||
new_1 = self._default_1
|
new_1 = self._default_1
|
||||||
|
|
||||||
if len(header) != 0:
|
if len(header) != 0:
|
||||||
for i in [0,1]:
|
for i in [0, 1]:
|
||||||
for j in range(len(header)):
|
for j in range(len(header)):
|
||||||
if self._header[i] == header[j]:
|
if self._header[i] == header[j]:
|
||||||
if i == 0:
|
if i == 0:
|
||||||
@@ -295,13 +302,13 @@ class LateralContribution(SQLSubModel):
|
|||||||
|
|
||||||
return (new_0, new_1)
|
return (new_0, new_1)
|
||||||
|
|
||||||
def add(self, index:int):
|
def add(self, index: int):
|
||||||
value = (self._default_0, self._default_1)
|
value = (self._default_0, self._default_1)
|
||||||
self._data.insert(index, value)
|
self._data.insert(index, value)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def insert(self, index:int, value):
|
def insert(self, index: int, value):
|
||||||
self._data.insert(index, value)
|
self._data.insert(index, value)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
@@ -337,11 +344,10 @@ class LateralContribution(SQLSubModel):
|
|||||||
return self.data[index]
|
return self.data[index]
|
||||||
|
|
||||||
def get_range(self, _range):
|
def get_range(self, _range):
|
||||||
l = []
|
lst = []
|
||||||
for r in _range:
|
for r in _range:
|
||||||
l.append(r)
|
lst.append(r)
|
||||||
return l
|
return lst
|
||||||
|
|
||||||
|
|
||||||
def _set_i_c_v(self, index, column, value):
|
def _set_i_c_v(self, index, column, value):
|
||||||
v = list(self._data[index])
|
v = list(self._data[index])
|
||||||
@@ -349,15 +355,15 @@ class LateralContribution(SQLSubModel):
|
|||||||
self._data[index] = tuple(v)
|
self._data[index] = tuple(v)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def set_i_0(self, index:int, value):
|
def set_i_0(self, index: int, value):
|
||||||
self._set_i_c_v(index, 0, value)
|
self._set_i_c_v(index, 0, value)
|
||||||
|
|
||||||
def set_i_1(self, index:int, value):
|
def set_i_1(self, index: int, value):
|
||||||
self._set_i_c_v(index, 1, value)
|
self._set_i_c_v(index, 1, value)
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def convert(self, cls):
|
def convert(self, cls):
|
||||||
new = cls(name = self.name, status = self._status)
|
new = cls(name=self.name, status=self._status)
|
||||||
new.edge = self.edge
|
new.edge = self.edge
|
||||||
new.begin_kp = self.begin_kp
|
new.begin_kp = self.begin_kp
|
||||||
new.end_kp = self.end_kp
|
new.end_kp = self.end_kp
|
||||||
@@ -365,8 +371,8 @@ class LateralContribution(SQLSubModel):
|
|||||||
for i, _ in enumerate(self.data):
|
for i, _ in enumerate(self.data):
|
||||||
new.add(i)
|
new.add(i)
|
||||||
|
|
||||||
for i in [0,1]:
|
for i in [0, 1]:
|
||||||
for j in [0,1]:
|
for j in [0, 1]:
|
||||||
if self._header[i] == new.header[j]:
|
if self._header[i] == new.header[j]:
|
||||||
for ind, v in self.data:
|
for ind, v in self.data:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
from copy import copy
|
from copy import copy
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrList import PamhyrModelListWithTab
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
from Model.LateralContribution.LateralContribution import LateralContribution
|
from Model.LateralContribution.LateralContribution import LateralContribution
|
||||||
@@ -27,46 +27,29 @@ from Model.LateralContribution.LateralContributionTypes import (
|
|||||||
NotDefined, LateralContrib, Rain, Evaporation,
|
NotDefined, LateralContrib, Rain, Evaporation,
|
||||||
)
|
)
|
||||||
|
|
||||||
class LateralContributionList(SQLSubModel):
|
|
||||||
|
class LateralContributionList(PamhyrModelListWithTab):
|
||||||
|
_tabs_list = ["liquid", "solid", "suspenssion"]
|
||||||
_sub_classes = [
|
_sub_classes = [
|
||||||
LateralContribution,
|
LateralContribution,
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, status = None):
|
|
||||||
super(LateralContributionList, self).__init__()
|
|
||||||
|
|
||||||
self._status = status
|
|
||||||
|
|
||||||
self._tabs = {
|
|
||||||
"liquid" : [],
|
|
||||||
"solid" : [],
|
|
||||||
"suspenssion" : []
|
|
||||||
}
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_load(cls, execute, data=None):
|
||||||
return cls._create_submodel(execute)
|
new = cls(status=data['status'])
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _sql_update(cls, execute, version):
|
|
||||||
return True
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _sql_load(cls, execute, data = None):
|
|
||||||
new = cls(status = data['status'])
|
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
for tab in new._tabs:
|
for tab in new._tabs:
|
||||||
data["tab"] = tab
|
data["tab"] = tab
|
||||||
new._tabs[tab] = LateralContribution._sql_load(
|
new._tabs[tab] = LateralContribution._db_load(
|
||||||
execute, data
|
execute, data
|
||||||
)
|
)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
execute("DELETE FROM lateral_contribution")
|
execute("DELETE FROM lateral_contribution")
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
@@ -75,83 +58,29 @@ class LateralContributionList(SQLSubModel):
|
|||||||
for tab in self._tabs:
|
for tab in self._tabs:
|
||||||
data["tab"] = tab
|
data["tab"] = tab
|
||||||
for lc in self._tabs[tab]:
|
for lc in self._tabs[tab]:
|
||||||
lc._sql_save(execute, data = data)
|
lc._db_save(execute, data=data)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def len(self, lst):
|
|
||||||
return len(self._tabs[lst])
|
|
||||||
|
|
||||||
def get_tab(self, lst):
|
|
||||||
return self._tabs[lst].copy()
|
|
||||||
|
|
||||||
def get(self, lst, row):
|
|
||||||
return self._tabs[lst][row]
|
|
||||||
|
|
||||||
def set(self, lst, row, new):
|
|
||||||
self._tabs[lst][row] = new
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def new(self, lst, index):
|
def new(self, lst, index):
|
||||||
n = NotDefined(status=self._status)
|
n = NotDefined(status=self._status)
|
||||||
self._tabs[lst].insert(index, n)
|
self._tabs[lst].insert(index, n)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def insert(self, lst, index, new):
|
|
||||||
self._tabs[lst].insert(index, new)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def delete(self, lst, bcs):
|
|
||||||
for bc in bcs:
|
|
||||||
self._tabs[lst].remove(bc)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def delete_i(self, lst, indexes):
|
|
||||||
bcs = list(
|
|
||||||
map(
|
|
||||||
lambda x: x[1],
|
|
||||||
filter(
|
|
||||||
lambda x: x[0] in indexes,
|
|
||||||
enumerate(self._tabs[lst])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.delete(lst, bcs)
|
|
||||||
|
|
||||||
def sort(self, lst, reverse=False, key=None):
|
|
||||||
self._tabs[lst].sort(reverse=reverse, key=key)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def move_up(self, lst, index):
|
|
||||||
if index < len(self._tabs[lst]):
|
|
||||||
next = index - 1
|
|
||||||
|
|
||||||
l = self._tabs[lst]
|
|
||||||
l[index], l[next] = l[next], l[index]
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def move_down(self, lst, index):
|
|
||||||
if index >= 0:
|
|
||||||
prev = index + 1
|
|
||||||
|
|
||||||
l = self._tabs[lst]
|
|
||||||
l[index], l[prev] = l[prev], l[index]
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def __copy__(self):
|
def __copy__(self):
|
||||||
new = LateralContributionList()
|
new = LateralContributionList()
|
||||||
|
|
||||||
for l in self._tabs:
|
for lst in self._tabs:
|
||||||
new.tabs[l] = self._tabs[l].copy()
|
new.tabs[lst] = self._tabs[lst].copy()
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def __deepcopy__(self):
|
def __deepcopy__(self):
|
||||||
new = LateralContributionList()
|
new = LateralContributionList()
|
||||||
|
|
||||||
for l in self._tabs:
|
for lst in self._tabs:
|
||||||
new.tabs[l] = self._tabs[l].deepcopy()
|
new.tabs[lst] = self._tabs[lst].deepcopy()
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from Model.LateralContribution.LateralContribution import LateralContribution
|
|||||||
|
|
||||||
|
|
||||||
class NotDefined(LateralContribution):
|
class NotDefined(LateralContribution):
|
||||||
def __init__(self, id:int = -1, name:str = "", status=None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
super(NotDefined, self).__init__(id=id, name=name, status=status)
|
super(NotDefined, self).__init__(id=id, name=name, status=status)
|
||||||
|
|
||||||
self._type = "ND"
|
self._type = "ND"
|
||||||
@@ -32,8 +32,9 @@ class NotDefined(LateralContribution):
|
|||||||
def _default_0(self):
|
def _default_0(self):
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
|
|
||||||
class LateralContrib(LateralContribution):
|
class LateralContrib(LateralContribution):
|
||||||
def __init__(self, id:int = -1, name:str = "", status=None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
super(LateralContrib, self).__init__(id=id, name=name, status=status)
|
super(LateralContrib, self).__init__(id=id, name=name, status=status)
|
||||||
|
|
||||||
self._type = "LC"
|
self._type = "LC"
|
||||||
@@ -44,8 +45,9 @@ class LateralContrib(LateralContribution):
|
|||||||
def compatibility(cls):
|
def compatibility(cls):
|
||||||
return ["liquid"]
|
return ["liquid"]
|
||||||
|
|
||||||
|
|
||||||
class Rain(LateralContribution):
|
class Rain(LateralContribution):
|
||||||
def __init__(self, id:int = -1, name:str = "", status=None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
super(Rain, self).__init__(id=id, name=name, status=status)
|
super(Rain, self).__init__(id=id, name=name, status=status)
|
||||||
|
|
||||||
self._type = "RA"
|
self._type = "RA"
|
||||||
@@ -56,8 +58,9 @@ class Rain(LateralContribution):
|
|||||||
def compatibility(cls):
|
def compatibility(cls):
|
||||||
return ["liquid"]
|
return ["liquid"]
|
||||||
|
|
||||||
|
|
||||||
class Evaporation(LateralContribution):
|
class Evaporation(LateralContribution):
|
||||||
def __init__(self, id:int = -1, name:str = "", status=None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
super(Evaporation, self).__init__(id=id, name=name, status=status)
|
super(Evaporation, self).__init__(id=id, name=name, status=status)
|
||||||
|
|
||||||
self._type = "EV"
|
self._type = "EV"
|
||||||
|
|||||||
@@ -18,13 +18,14 @@
|
|||||||
|
|
||||||
from Model.Network.Node import Node
|
from Model.Network.Node import Node
|
||||||
|
|
||||||
|
|
||||||
class Edge(object):
|
class Edge(object):
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
|
|
||||||
def __init__(self, id:int, name:str,
|
def __init__(self, id: int, name: str,
|
||||||
node1:Node = None,
|
node1: Node = None,
|
||||||
node2:Node = None,
|
node2: Node = None,
|
||||||
status = None):
|
status=None):
|
||||||
super(Edge, self).__init__()
|
super(Edge, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -74,7 +75,10 @@ class Edge(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self._name if self._name != "" else f"{self.node1.name} -> {self.node2.name}"
|
name = self._name
|
||||||
|
if self._name == "":
|
||||||
|
name = f"{self.node1.name} -> {self.node2.name}"
|
||||||
|
return name
|
||||||
|
|
||||||
def is_enable(self):
|
def is_enable(self):
|
||||||
return self._enable
|
return self._enable
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ from functools import reduce
|
|||||||
from Model.Network.Node import Node
|
from Model.Network.Node import Node
|
||||||
from Model.Network.Edge import Edge
|
from Model.Network.Edge import Edge
|
||||||
|
|
||||||
|
|
||||||
class Graph(object):
|
class Graph(object):
|
||||||
def __init__(self, status = None):
|
def __init__(self, status=None):
|
||||||
super(Graph, self).__init__()
|
super(Graph, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -83,7 +84,7 @@ class Graph(object):
|
|||||||
False
|
False
|
||||||
)
|
)
|
||||||
|
|
||||||
def node(self, node_name:str):
|
def node(self, node_name: str):
|
||||||
node = list(
|
node = list(
|
||||||
filter(
|
filter(
|
||||||
lambda n: n.name == node_name,
|
lambda n: n.name == node_name,
|
||||||
@@ -96,7 +97,7 @@ class Graph(object):
|
|||||||
|
|
||||||
return node[0]
|
return node[0]
|
||||||
|
|
||||||
def edge(self, edge_name:str):
|
def edge(self, edge_name: str):
|
||||||
edge = list(
|
edge = list(
|
||||||
filter(
|
filter(
|
||||||
lambda e: e.name == edge_name,
|
lambda e: e.name == edge_name,
|
||||||
@@ -109,12 +110,12 @@ class Graph(object):
|
|||||||
|
|
||||||
return edge[0]
|
return edge[0]
|
||||||
|
|
||||||
def _create_node(self, x:float, y:float):
|
def _create_node(self, x: float, y: float):
|
||||||
node = self._node_ctor(
|
node = self._node_ctor(
|
||||||
-1,
|
-1,
|
||||||
"",
|
"",
|
||||||
x = x, y = y,
|
x=x, y=y,
|
||||||
status = self._status
|
status=self._status
|
||||||
)
|
)
|
||||||
return node
|
return node
|
||||||
|
|
||||||
@@ -123,14 +124,14 @@ class Graph(object):
|
|||||||
self._status.modified()
|
self._status.modified()
|
||||||
return node
|
return node
|
||||||
|
|
||||||
def add_node(self, x:float = 0.0, y:float = 0.0):
|
def add_node(self, x: float = 0.0, y: float = 0.0):
|
||||||
node = self._create_node(x, y)
|
node = self._create_node(x, y)
|
||||||
return self._add_node(node)
|
return self._add_node(node)
|
||||||
|
|
||||||
def insert_node(self, node):
|
def insert_node(self, node):
|
||||||
return self._add_node(node)
|
return self._add_node(node)
|
||||||
|
|
||||||
def remove_node(self, node_name:str):
|
def remove_node(self, node_name: str):
|
||||||
self._nodes = list(
|
self._nodes = list(
|
||||||
filter(
|
filter(
|
||||||
lambda n: n.name != node_name,
|
lambda n: n.name != node_name,
|
||||||
@@ -139,19 +140,18 @@ class Graph(object):
|
|||||||
)
|
)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def create_node(self, x:float = 0.0, y:float = 0.0):
|
def create_node(self, x: float = 0.0, y: float = 0.0):
|
||||||
node = self._create_node(x, y)
|
node = self._create_node(x, y)
|
||||||
return node
|
return node
|
||||||
|
|
||||||
def _create_edge(self, n1:Node, n2:Node):
|
def _create_edge(self, n1: Node, n2: Node):
|
||||||
edge = self._edge_ctor(
|
edge = self._edge_ctor(
|
||||||
-1,
|
-1,
|
||||||
"", n1, n2,
|
"", n1, n2,
|
||||||
status = self._status
|
status=self._status
|
||||||
)
|
)
|
||||||
return edge
|
return edge
|
||||||
|
|
||||||
|
|
||||||
def _add_edge(self, edge):
|
def _add_edge(self, edge):
|
||||||
# This edge already exists ?
|
# This edge already exists ?
|
||||||
if any(filter(lambda e: (e.node1 == edge.node1 and
|
if any(filter(lambda e: (e.node1 == edge.node1 and
|
||||||
@@ -164,17 +164,17 @@ class Graph(object):
|
|||||||
self._status.modified()
|
self._status.modified()
|
||||||
return edge
|
return edge
|
||||||
|
|
||||||
def add_edge(self, n1:Node, n2:Node):
|
def add_edge(self, n1: Node, n2: Node):
|
||||||
edge = self._create_edge(n1, n2)
|
edge = self._create_edge(n1, n2)
|
||||||
return self._add_edge(edge)
|
return self._add_edge(edge)
|
||||||
|
|
||||||
def insert_edge(self, edge):
|
def insert_edge(self, edge):
|
||||||
return self._add_edge(edge)
|
return self._add_edge(edge)
|
||||||
|
|
||||||
def create_edge(self, n1:Node, n2:Node):
|
def create_edge(self, n1: Node, n2: Node):
|
||||||
return self._create_edge(n1, n2)
|
return self._create_edge(n1, n2)
|
||||||
|
|
||||||
def remove_edge(self, edge_name:str):
|
def remove_edge(self, edge_name: str):
|
||||||
self._edges = list(
|
self._edges = list(
|
||||||
filter(
|
filter(
|
||||||
lambda e: e.name != edge_name,
|
lambda e: e.name != edge_name,
|
||||||
|
|||||||
@@ -18,12 +18,13 @@
|
|||||||
|
|
||||||
from Model.Network.Point import Point
|
from Model.Network.Point import Point
|
||||||
|
|
||||||
|
|
||||||
class Node(object):
|
class Node(object):
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
|
|
||||||
def __init__(self, id:int, name:str,
|
def __init__(self, id: int, name: str,
|
||||||
x:float = 0.0, y:float = 0.0,
|
x: float = 0.0, y: float = 0.0,
|
||||||
status = None):
|
status=None):
|
||||||
super(Node, self).__init__()
|
super(Node, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -73,7 +74,6 @@ class Node(object):
|
|||||||
def y(self):
|
def y(self):
|
||||||
return self.pos.y
|
return self.pos.y
|
||||||
|
|
||||||
|
|
||||||
def setPos(self, x, y):
|
def setPos(self, x, y):
|
||||||
self.pos.x = x
|
self.pos.x = x
|
||||||
self.pos.y = y
|
self.pos.y = y
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
class Point(object):
|
class Point(object):
|
||||||
def __init__(self, x:float, y:float):
|
def __init__(self, x: float, y: float):
|
||||||
super(Point, self).__init__()
|
super(Point, self).__init__()
|
||||||
|
|
||||||
self.x = x
|
self.x = x
|
||||||
|
|||||||
@@ -0,0 +1,268 @@
|
|||||||
|
# Reservoir.py -- Pamhyr
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class Reservoir(SQLSubModel):
|
||||||
|
_sub_classes = []
|
||||||
|
_id_cnt = 0
|
||||||
|
|
||||||
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
|
status=None):
|
||||||
|
super(Reservoir, self).__init__()
|
||||||
|
|
||||||
|
self._status = status
|
||||||
|
|
||||||
|
if id == -1:
|
||||||
|
self.id = Reservoir._id_cnt
|
||||||
|
else:
|
||||||
|
self.id = id
|
||||||
|
|
||||||
|
self._name = name
|
||||||
|
self._node = None
|
||||||
|
self._data = []
|
||||||
|
|
||||||
|
Reservoir._id_cnt = max(Reservoir._id_cnt + 1, self.id)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_create(cls, execute):
|
||||||
|
execute("""
|
||||||
|
CREATE TABLE reservoir(
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
node INTEGER,
|
||||||
|
FOREIGN KEY(node) REFERENCES river_node(id)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
execute("""
|
||||||
|
CREATE TABLE reservoir_data(
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
ind INTEGER NOT NULL,
|
||||||
|
elevation REAL NOT NULL,
|
||||||
|
surface REAL NOT NULL,
|
||||||
|
reservoir INTEGER,
|
||||||
|
FOREIGN KEY(reservoir) REFERENCES reservoir(id)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_update(cls, execute, version):
|
||||||
|
major, minor, release = version.strip().split(".")
|
||||||
|
if major == minor == "0":
|
||||||
|
if int(release) < 5:
|
||||||
|
cls._db_create(execute)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_load(cls, execute, data=None):
|
||||||
|
new = []
|
||||||
|
|
||||||
|
table = execute(
|
||||||
|
"SELECT id, name, node " +
|
||||||
|
"FROM reservoir "
|
||||||
|
)
|
||||||
|
|
||||||
|
for row in table:
|
||||||
|
id = row[0]
|
||||||
|
name = row[1]
|
||||||
|
node_id = row[2]
|
||||||
|
new_reservoir = cls(id, name, status=data["status"])
|
||||||
|
|
||||||
|
new_reservoir._node = None
|
||||||
|
if node_id != -1:
|
||||||
|
new_reservoir._node = next(filter(lambda n: n.id == node_id, data["nodes"]))
|
||||||
|
|
||||||
|
new_data = []
|
||||||
|
table = execute(
|
||||||
|
"SELECT elevation, surface " +
|
||||||
|
"FROM reservoir_data " +
|
||||||
|
f"WHERE reservoir = {id} " +
|
||||||
|
"ORDER BY ind ASC"
|
||||||
|
)
|
||||||
|
for t in table:
|
||||||
|
new_data.append((t[0], t[1]))
|
||||||
|
|
||||||
|
new_reservoir._data = new_data
|
||||||
|
|
||||||
|
new.append(new_reservoir)
|
||||||
|
|
||||||
|
return new
|
||||||
|
|
||||||
|
def _db_save(self, execute, data=None):
|
||||||
|
|
||||||
|
execute(f"DELETE FROM reservoir WHERE id = {self.id}")
|
||||||
|
execute(f"DELETE FROM reservoir_data WHERE reservoir = {self.id}")
|
||||||
|
|
||||||
|
node_id = -1
|
||||||
|
if self._node is not None:
|
||||||
|
node_id = self._node.id
|
||||||
|
|
||||||
|
sql = (
|
||||||
|
"INSERT INTO " +
|
||||||
|
"reservoir(id, name, node) " +
|
||||||
|
"VALUES (" +
|
||||||
|
f"{self.id}, '{self._db_format(self._name)}', " +
|
||||||
|
f"{node_id}" +
|
||||||
|
")"
|
||||||
|
)
|
||||||
|
execute(sql)
|
||||||
|
|
||||||
|
ind = 0
|
||||||
|
for d in self._data:
|
||||||
|
sql = (
|
||||||
|
"INSERT INTO " +
|
||||||
|
"reservoir_data(ind, elevation, surface, reservoir) " +
|
||||||
|
f"VALUES ({ind}, '{d[0]}', {d[1]}, {self.id})"
|
||||||
|
)
|
||||||
|
execute(sql)
|
||||||
|
ind += 1
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self._data)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@name.setter
|
||||||
|
def name(self, name):
|
||||||
|
self._name = name
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def node(self):
|
||||||
|
return self._node
|
||||||
|
|
||||||
|
@node.setter
|
||||||
|
def node(self, node):
|
||||||
|
self._node = node
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def has_node(self):
|
||||||
|
return self._node is not None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def data(self):
|
||||||
|
return self._data.copy()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _default_elevation(self):
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _default_surface(self):
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
def is_define(self):
|
||||||
|
return len(self._data) != 0
|
||||||
|
|
||||||
|
def new_from_data(self, data):
|
||||||
|
|
||||||
|
try:
|
||||||
|
new_0 = float(data[0])
|
||||||
|
new_1 = float(data[1])
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
|
new_0 = None
|
||||||
|
new_1 = None
|
||||||
|
|
||||||
|
return (new_0, new_1)
|
||||||
|
|
||||||
|
def add(self, index: int):
|
||||||
|
value = (self._default_elevation, self._default_surface)
|
||||||
|
self._data.insert(index, value)
|
||||||
|
self._status.modified()
|
||||||
|
return value
|
||||||
|
|
||||||
|
def insert(self, index: int, value):
|
||||||
|
self._data.insert(index, value)
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def delete_i(self, indexes):
|
||||||
|
self._data = list(
|
||||||
|
map(
|
||||||
|
lambda e: e[1],
|
||||||
|
filter(
|
||||||
|
lambda e: e[0] not in indexes,
|
||||||
|
enumerate(self.data)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def delete(self, els):
|
||||||
|
self._data = list(
|
||||||
|
filter(
|
||||||
|
lambda e: e not in els,
|
||||||
|
self.data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def sort(self, _reverse=False, key=None):
|
||||||
|
if key is None:
|
||||||
|
self._data.sort(reverse=_reverse)
|
||||||
|
else:
|
||||||
|
self._data.sort(reverse=_reverse, key=key)
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def get_i(self, index):
|
||||||
|
return self.data[index]
|
||||||
|
|
||||||
|
def get_range(self, _range):
|
||||||
|
lst = []
|
||||||
|
for r in _range:
|
||||||
|
lst.append(r)
|
||||||
|
return lst
|
||||||
|
|
||||||
|
def _set_i_c_v(self, index, column, value):
|
||||||
|
v = list(self._data[index])
|
||||||
|
v[column] = value
|
||||||
|
self._data[index] = tuple(v)
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def set_i_elevation(self, index: int, value):
|
||||||
|
self._set_i_c_v(index, 0, value)
|
||||||
|
|
||||||
|
def set_i_surface(self, index: int, value):
|
||||||
|
self._set_i_c_v(index, 1, value)
|
||||||
|
|
||||||
|
def move_up(self, index):
|
||||||
|
if index < len(self):
|
||||||
|
next = index - 1
|
||||||
|
d = self._data
|
||||||
|
d[index], d[next] = d[next], d[index]
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def move_down(self, index):
|
||||||
|
if index >= 0:
|
||||||
|
prev = index + 1
|
||||||
|
d = self._data
|
||||||
|
d[index], d[prev] = d[prev], d[index]
|
||||||
|
self._status.modified()
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
# ReservoirList.py -- Pamhyr
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from copy import copy
|
||||||
|
from tools import trace, timer
|
||||||
|
|
||||||
|
from Model.Tools.PamhyrList import PamhyrModelList
|
||||||
|
from Model.Reservoir.Reservoir import Reservoir
|
||||||
|
|
||||||
|
|
||||||
|
class ReservoirList(PamhyrModelList):
|
||||||
|
_sub_classes = [
|
||||||
|
Reservoir,
|
||||||
|
]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_load(cls, execute, data=None):
|
||||||
|
new = cls(status=data['status'])
|
||||||
|
|
||||||
|
new._lst = Reservoir._db_load(
|
||||||
|
execute, data
|
||||||
|
)
|
||||||
|
|
||||||
|
return new
|
||||||
|
|
||||||
|
def _db_save(self, execute, data=None):
|
||||||
|
execute("DELETE FROM reservoir")
|
||||||
|
execute("DELETE FROM reservoir_data")
|
||||||
|
|
||||||
|
if data is None:
|
||||||
|
data = {}
|
||||||
|
|
||||||
|
for reservoir in self._lst:
|
||||||
|
reservoir._db_save(execute, data=data)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def new(self, index):
|
||||||
|
r = Reservoir(status=self._status)
|
||||||
|
self._lst.insert(index, r)
|
||||||
|
self._status.modified()
|
||||||
|
return r
|
||||||
|
|
||||||
|
def __copy__(self):
|
||||||
|
new = ReservoirList()
|
||||||
|
|
||||||
|
new._lst = self._lst.copy()
|
||||||
|
|
||||||
|
return new
|
||||||
|
|
||||||
|
def __deepcopy__(self):
|
||||||
|
new = ReservoirList()
|
||||||
|
|
||||||
|
new._lst = self._lst.deepcopy()
|
||||||
|
|
||||||
|
return new
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
return copy(self)
|
||||||
|
|
||||||
|
def get_assoc_to_node(self, node):
|
||||||
|
assoc = list(
|
||||||
|
filter(
|
||||||
|
lambda i: i.node is node,
|
||||||
|
self._lst
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(assoc) > 0:
|
||||||
|
return assoc[0]
|
||||||
|
|
||||||
|
return None
|
||||||
@@ -24,9 +24,15 @@ from Model.Results.River.River import River
|
|||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class Results(object):
|
class Results(object):
|
||||||
def __init__(self, study = None):
|
def __init__(self, study=None, solver=None,
|
||||||
|
repertory="", name="0"):
|
||||||
self._study = study
|
self._study = study
|
||||||
|
self._solver = solver
|
||||||
|
self._repertory = repertory
|
||||||
|
self._name = name
|
||||||
|
|
||||||
self._river = River(self._study)
|
self._river = River(self._study)
|
||||||
|
|
||||||
self._meta_data = {
|
self._meta_data = {
|
||||||
@@ -43,8 +49,19 @@ class Results(object):
|
|||||||
def river(self):
|
def river(self):
|
||||||
return self._river
|
return self._river
|
||||||
|
|
||||||
|
@property
|
||||||
|
def study(self):
|
||||||
|
return self._study
|
||||||
|
|
||||||
def set(self, key, value):
|
def set(self, key, value):
|
||||||
self._meta_data[key] = value
|
self._meta_data[key] = value
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
return self._meta_data[key]
|
return self._meta_data[key]
|
||||||
|
|
||||||
|
def reload(self):
|
||||||
|
return self._solver.results(
|
||||||
|
self._study,
|
||||||
|
self._repertory,
|
||||||
|
qlog=None,
|
||||||
|
)
|
||||||
@@ -20,11 +20,15 @@ from datetime import datetime
|
|||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class Profile(object):
|
class Profile(object):
|
||||||
def __init__(self, profile, study):
|
def __init__(self, profile, study):
|
||||||
self._study = study
|
self._study = study
|
||||||
self._profile = profile # Source profile in the study
|
self._profile = profile # Source profile in the study
|
||||||
self._data = {} # Dict of dict {<ts>: {<key>: <value>, ...}, ...}
|
self._data = {} # Dict of dict {<ts>: {<key>: <value>, ...}, ...}
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self._data)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@@ -55,10 +59,11 @@ class Profile(object):
|
|||||||
def get_ts_key(self, timestamp, key):
|
def get_ts_key(self, timestamp, key):
|
||||||
return self._data[timestamp][key]
|
return self._data[timestamp][key]
|
||||||
|
|
||||||
|
|
||||||
class Reach(object):
|
class Reach(object):
|
||||||
def __init__(self, reach, study):
|
def __init__(self, reach, study):
|
||||||
self._study = study
|
self._study = study
|
||||||
self._reach = reach # Source reach in the study
|
self._reach = reach # Source reach in the study
|
||||||
self._profiles = list(
|
self._profiles = list(
|
||||||
map(
|
map(
|
||||||
lambda p: Profile(p, self._study),
|
lambda p: Profile(p, self._study),
|
||||||
@@ -66,6 +71,9 @@ class Reach(object):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self._profiles)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self._reach.name
|
return self._reach.name
|
||||||
@@ -84,6 +92,7 @@ class Reach(object):
|
|||||||
def set(self, profile_id, timestamp, key, data):
|
def set(self, profile_id, timestamp, key, data):
|
||||||
self._profiles[profile_id].set(timestamp, key, data)
|
self._profiles[profile_id].set(timestamp, key, data)
|
||||||
|
|
||||||
|
|
||||||
class River(object):
|
class River(object):
|
||||||
def __init__(self, study):
|
def __init__(self, study):
|
||||||
self._study = study
|
self._study = study
|
||||||
@@ -91,6 +100,9 @@ class River(object):
|
|||||||
# Dict with timestamps as key
|
# Dict with timestamps as key
|
||||||
self._reachs = []
|
self._reachs = []
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self._reachs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def reachs(self):
|
def reachs(self):
|
||||||
return self._reachs.copy()
|
return self._reachs.copy()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
from tools import flatten
|
from tools import flatten
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
|
||||||
from Model.Network.Node import Node
|
from Model.Network.Node import Node
|
||||||
from Model.Network.Edge import Edge
|
from Model.Network.Edge import Edge
|
||||||
@@ -28,31 +28,35 @@ from Model.Geometry.Profile import Profile
|
|||||||
from Model.Geometry.Reach import Reach
|
from Model.Geometry.Reach import Reach
|
||||||
|
|
||||||
from Model.BoundaryCondition.BoundaryConditionList import BoundaryConditionList
|
from Model.BoundaryCondition.BoundaryConditionList import BoundaryConditionList
|
||||||
from Model.LateralContribution.LateralContributionList import LateralContributionList
|
from Model.LateralContribution.LateralContributionList import (
|
||||||
|
LateralContributionList
|
||||||
|
)
|
||||||
from Model.InitialConditions.InitialConditionsDict import InitialConditionsDict
|
from Model.InitialConditions.InitialConditionsDict import InitialConditionsDict
|
||||||
from Model.Stricklers.StricklersList import StricklersList
|
from Model.Stricklers.StricklersList import StricklersList
|
||||||
from Model.Friction.FrictionList import FrictionList
|
from Model.Friction.FrictionList import FrictionList
|
||||||
from Model.SolverParameters.SolverParametersList import SolverParametersList
|
from Model.SolverParameters.SolverParametersList import SolverParametersList
|
||||||
from Model.SedimentLayer.SedimentLayerList import SedimentLayerList
|
from Model.SedimentLayer.SedimentLayerList import SedimentLayerList
|
||||||
|
from Model.Reservoir.ReservoirList import ReservoirList
|
||||||
|
|
||||||
from Solver.Solvers import solver_type_list
|
from Solver.Solvers import solver_type_list
|
||||||
|
|
||||||
|
|
||||||
class RiverNode(Node, SQLSubModel):
|
class RiverNode(Node, SQLSubModel):
|
||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
|
|
||||||
def __init__(self, id:str, name:str,
|
def __init__(self, id: str, name: str,
|
||||||
x:float, y:float,
|
x: float, y: float,
|
||||||
status = None):
|
status=None):
|
||||||
super(RiverNode, self).__init__(
|
super(RiverNode, self).__init__(
|
||||||
id, name,
|
id, name,
|
||||||
x, y,
|
x, y,
|
||||||
status = status
|
status=status
|
||||||
)
|
)
|
||||||
|
|
||||||
self._locker = None
|
self._locker = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE river_node(
|
CREATE TABLE river_node(
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
@@ -66,11 +70,11 @@ class RiverNode(Node, SQLSubModel):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
nodes = []
|
nodes = []
|
||||||
|
|
||||||
table = execute("SELECT id, name, x, y FROM river_node")
|
table = execute("SELECT id, name, x, y FROM river_node")
|
||||||
@@ -82,11 +86,11 @@ class RiverNode(Node, SQLSubModel):
|
|||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT OR REPLACE INTO river_node(id, name, x, y) VALUES (" +
|
"INSERT OR REPLACE INTO river_node(id, name, x, y) VALUES (" +
|
||||||
f"{self.id}, '{self._sql_format(self.name)}', " +
|
f"{self.id}, '{self._db_format(self.name)}', " +
|
||||||
f"{self.x}, {self.y}"+
|
f"{self.x}, {self.y}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
@@ -108,21 +112,21 @@ class RiverReach(Edge, SQLSubModel):
|
|||||||
FrictionList,
|
FrictionList,
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, id:str, name:str,
|
def __init__(self, id: str, name: str,
|
||||||
node1:RiverNode = None,
|
node1: RiverNode = None,
|
||||||
node2:RiverNode = None,
|
node2: RiverNode = None,
|
||||||
status = None):
|
status=None):
|
||||||
super(RiverReach, self).__init__(
|
super(RiverReach, self).__init__(
|
||||||
id, name,
|
id, name,
|
||||||
node1, node2,
|
node1, node2,
|
||||||
status = status
|
status=status
|
||||||
)
|
)
|
||||||
|
|
||||||
self._reach = Reach(status=self._status, parent=self)
|
self._reach = Reach(status=self._status, parent=self)
|
||||||
self._frictions = FrictionList(status = self._status)
|
self._frictions = FrictionList(status=self._status)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE river_reach(
|
CREATE TABLE river_reach(
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
@@ -139,17 +143,18 @@ class RiverReach(Edge, SQLSubModel):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
return cls._update_submodel(execute, version)
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
reachs = []
|
reachs = []
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
table = execute("SELECT id, name, enable, node1, node2 FROM river_reach")
|
table = execute(
|
||||||
|
"SELECT id, name, enable, node1, node2 FROM river_reach")
|
||||||
for row in table:
|
for row in table:
|
||||||
# Update id counter
|
# Update id counter
|
||||||
cls._id_cnt = max(cls._id_cnt, row[0])
|
cls._id_cnt = max(cls._id_cnt, row[0])
|
||||||
@@ -161,27 +166,27 @@ class RiverReach(Edge, SQLSubModel):
|
|||||||
node1 = next(filter(lambda n: n.id == row[3], data["nodes"]))
|
node1 = next(filter(lambda n: n.id == row[3], data["nodes"]))
|
||||||
node2 = next(filter(lambda n: n.id == row[4], data["nodes"]))
|
node2 = next(filter(lambda n: n.id == row[4], data["nodes"]))
|
||||||
|
|
||||||
new = cls(id, name, node1, node2, status = data["status"])
|
new = cls(id, name, node1, node2, status=data["status"])
|
||||||
new.enable(enable = enable)
|
new.enable(enable=enable)
|
||||||
|
|
||||||
data["reach"] = id
|
data["reach"] = id
|
||||||
data["parent"] = new
|
data["parent"] = new
|
||||||
new._reach = Reach._sql_load(execute, data)
|
new._reach = Reach._db_load(execute, data)
|
||||||
|
|
||||||
new._frictions = FrictionList._sql_load(execute, data)
|
new._frictions = FrictionList._db_load(execute, data)
|
||||||
|
|
||||||
reachs.append(new)
|
reachs.append(new)
|
||||||
|
|
||||||
return reachs
|
return reachs
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT OR REPLACE INTO " +
|
"INSERT OR REPLACE INTO " +
|
||||||
"river_reach(id, name, enable, node1, node2) "+
|
"river_reach(id, name, enable, node1, node2) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, '{self._sql_format(self._name)}', " +
|
f"{self.id}, '{self._db_format(self._name)}', " +
|
||||||
f"{self._sql_format(self.is_enable())},"
|
f"{self._db_format(self.is_enable())},"
|
||||||
f"{self.node1.id}, {self.node2.id}"+
|
f"{self.node1.id}, {self.node2.id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
@@ -202,6 +207,7 @@ class RiverReach(Edge, SQLSubModel):
|
|||||||
def frictions(self):
|
def frictions(self):
|
||||||
return self._frictions
|
return self._frictions
|
||||||
|
|
||||||
|
|
||||||
class River(Graph, SQLSubModel):
|
class River(Graph, SQLSubModel):
|
||||||
_sub_classes = [
|
_sub_classes = [
|
||||||
RiverNode,
|
RiverNode,
|
||||||
@@ -212,6 +218,7 @@ class River(Graph, SQLSubModel):
|
|||||||
StricklersList,
|
StricklersList,
|
||||||
SolverParametersList,
|
SolverParametersList,
|
||||||
SedimentLayerList,
|
SedimentLayerList,
|
||||||
|
ReservoirList,
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, status=None):
|
def __init__(self, status=None):
|
||||||
@@ -223,87 +230,95 @@ class River(Graph, SQLSubModel):
|
|||||||
|
|
||||||
self._current_reach = None
|
self._current_reach = None
|
||||||
self._boundary_condition = BoundaryConditionList(status=self._status)
|
self._boundary_condition = BoundaryConditionList(status=self._status)
|
||||||
self._lateral_contribution = LateralContributionList(status=self._status)
|
self._lateral_contribution = LateralContributionList(
|
||||||
|
status=self._status)
|
||||||
self._initial_conditions = InitialConditionsDict(status=self._status)
|
self._initial_conditions = InitialConditionsDict(status=self._status)
|
||||||
self._stricklers = StricklersList(status=self._status)
|
self._stricklers = StricklersList(status=self._status)
|
||||||
self._parameters = {}
|
self._parameters = {}
|
||||||
self._sediment_layers = SedimentLayerList(status=self._status)
|
self._sediment_layers = SedimentLayerList(status=self._status)
|
||||||
|
self._reservoir = ReservoirList(status=self._status)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
cls._create_submodel(execute)
|
cls._create_submodel(execute)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
cls._update_submodel(execute, version)
|
cls._update_submodel(execute, version)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = cls(data["status"])
|
new = cls(data["status"])
|
||||||
|
|
||||||
# Stricklers (Stricklers is load in first because it's needed
|
# Stricklers (Stricklers is load in first because it's needed
|
||||||
# for reachs)
|
# for reachs)
|
||||||
new._stricklers = StricklersList._sql_load(
|
new._stricklers = StricklersList._db_load(
|
||||||
execute,
|
execute,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
data["stricklers"] = new._stricklers
|
data["stricklers"] = new._stricklers
|
||||||
|
|
||||||
|
|
||||||
# Initial conditions
|
# Initial conditions
|
||||||
new._sediment_layers = SedimentLayerList._sql_load(
|
new._sediment_layers = SedimentLayerList._db_load(
|
||||||
execute,
|
execute,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
data["sediment_layers_list"] = new._sediment_layers
|
data["sediment_layers_list"] = new._sediment_layers
|
||||||
|
|
||||||
# Network
|
# Network
|
||||||
new._nodes = RiverNode._sql_load(
|
new._nodes = RiverNode._db_load(
|
||||||
execute,
|
execute,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
data["nodes"] = new.nodes()
|
data["nodes"] = new.nodes()
|
||||||
|
|
||||||
new._edges = RiverReach._sql_load(
|
new._edges = RiverReach._db_load(
|
||||||
execute,
|
execute,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
data["edges"] = new.edges()
|
data["edges"] = new.edges()
|
||||||
|
|
||||||
# Boundary Condition
|
# Boundary Condition
|
||||||
new._boundary_condition = BoundaryConditionList._sql_load(
|
new._boundary_condition = BoundaryConditionList._db_load(
|
||||||
execute,
|
execute,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
# Lateral Contribution
|
# Lateral Contribution
|
||||||
new._lateral_contribution = LateralContributionList._sql_load(
|
new._lateral_contribution = LateralContributionList._db_load(
|
||||||
execute,
|
execute,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|
||||||
# Initial conditions
|
# Initial conditions
|
||||||
new._initial_conditions = InitialConditionsDict._sql_load(
|
new._initial_conditions = InitialConditionsDict._db_load(
|
||||||
|
execute,
|
||||||
|
data
|
||||||
|
)
|
||||||
|
|
||||||
|
# Reservoir
|
||||||
|
new._reservoir = ReservoirList._db_load(
|
||||||
execute,
|
execute,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|
||||||
# Parameters
|
# Parameters
|
||||||
new._parameters = SolverParametersList._sql_load(
|
new._parameters = SolverParametersList._db_load(
|
||||||
execute,
|
execute,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
objs = (self._nodes + self._edges)
|
objs = (self._nodes + self._edges)
|
||||||
objs.append(self._boundary_condition)
|
objs.append(self._boundary_condition)
|
||||||
objs.append(self._initial_conditions)
|
objs.append(self._initial_conditions)
|
||||||
objs.append(self._lateral_contribution)
|
objs.append(self._lateral_contribution)
|
||||||
objs.append(self._sediment_layers)
|
objs.append(self._sediment_layers)
|
||||||
objs.append(self._stricklers)
|
objs.append(self._stricklers)
|
||||||
|
objs.append(self._reservoir)
|
||||||
|
|
||||||
for solver in self._parameters:
|
for solver in self._parameters:
|
||||||
objs.append(self._parameters[solver])
|
objs.append(self._parameters[solver])
|
||||||
@@ -311,10 +326,6 @@ class River(Graph, SQLSubModel):
|
|||||||
self._save_submodel(execute, objs, data)
|
self._save_submodel(execute, objs, data)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@property
|
|
||||||
def frictions(self):
|
|
||||||
return self._frictions
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def boundary_condition(self):
|
def boundary_condition(self):
|
||||||
return self._boundary_condition
|
return self._boundary_condition
|
||||||
@@ -348,6 +359,9 @@ class River(Graph, SQLSubModel):
|
|||||||
|
|
||||||
return ret[0]
|
return ret[0]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reservoir(self):
|
||||||
|
return self._reservoir
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parameters(self):
|
def parameters(self):
|
||||||
@@ -358,8 +372,8 @@ class River(Graph, SQLSubModel):
|
|||||||
return self._parameters[solver]
|
return self._parameters[solver]
|
||||||
|
|
||||||
new = SolverParametersList(
|
new = SolverParametersList(
|
||||||
solver_type = solver_type_list[solver],
|
solver_type=solver_type_list[solver],
|
||||||
status = self._status
|
status=self._status
|
||||||
)
|
)
|
||||||
self._parameters[solver] = new
|
self._parameters[solver] = new
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
@@ -385,7 +399,7 @@ class River(Graph, SQLSubModel):
|
|||||||
has = len(self._sediment_layers) != 0
|
has = len(self._sediment_layers) != 0
|
||||||
has &= any(
|
has &= any(
|
||||||
filter(
|
filter(
|
||||||
lambda p: p.sl != None,
|
lambda p: p.sl is not None,
|
||||||
flatten(
|
flatten(
|
||||||
map(lambda e: e.reach.profiles, self.edges())
|
map(lambda e: e.reach.profiles, self.edges())
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import logging
|
|||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class SavedStatus(object):
|
class SavedStatus(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(SavedStatus, self).__init__()
|
super(SavedStatus, self).__init__()
|
||||||
|
|||||||
@@ -2,19 +2,20 @@
|
|||||||
|
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
|
|
||||||
class Layer(SQLSubModel):
|
class Layer(SQLSubModel):
|
||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
id:int = -1, name:str = "",
|
id: int = -1, name: str = "",
|
||||||
type = "",
|
type="",
|
||||||
height = 0.0, d50 = 0.0, sigma = 0.0,
|
height=0.0, d50=0.0, sigma=0.0,
|
||||||
critical_constraint = 0.0,
|
critical_constraint=0.0,
|
||||||
sl = None, status = None):
|
sl=None, status=None):
|
||||||
super(Layer, self).__init__()
|
super(Layer, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -83,7 +84,7 @@ class Layer(SQLSubModel):
|
|||||||
self._critical_constraint = float(critical_constraint)
|
self._critical_constraint = float(critical_constraint)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE sedimentary_layer_layer(
|
CREATE TABLE sedimentary_layer_layer(
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
@@ -102,21 +103,22 @@ class Layer(SQLSubModel):
|
|||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
if major == minor == "0":
|
if major == minor == "0":
|
||||||
if int(release) < 2:
|
if int(release) < 2:
|
||||||
cls._sql_create(execute)
|
cls._db_create(execute)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
sl = data["sl"]
|
sl = data["sl"]
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT id, ind, name, type, height, d50, sigma, critical_constraint " +
|
"SELECT id, ind, name, type, height, " +
|
||||||
|
"d50, sigma, critical_constraint " +
|
||||||
"FROM sedimentary_layer_layer " +
|
"FROM sedimentary_layer_layer " +
|
||||||
f"WHERE sl = {sl}"
|
f"WHERE sl = {sl}"
|
||||||
)
|
)
|
||||||
@@ -128,27 +130,28 @@ class Layer(SQLSubModel):
|
|||||||
ind = row[1]
|
ind = row[1]
|
||||||
|
|
||||||
layer = cls(
|
layer = cls(
|
||||||
id = row[0], name = row[2],
|
id=row[0], name=row[2],
|
||||||
type = row[3], height = row[4],
|
type=row[3], height=row[4],
|
||||||
d50 = row[5], sigma = row[6],
|
d50=row[5], sigma=row[6],
|
||||||
critical_constraint = row[7],
|
critical_constraint=row[7],
|
||||||
sl = sl, status = data['status']
|
sl=sl, status=data['status']
|
||||||
)
|
)
|
||||||
|
|
||||||
new[ind] = layer
|
new[ind] = layer
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
ind = data["ind"]
|
ind = data["ind"]
|
||||||
sl = data["sl"]
|
sl = data["sl"]
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"sedimentary_layer_layer(id, ind, name, type, height, d50, sigma, critical_constraint, sl) "+
|
"sedimentary_layer_layer(id, ind, name, type, height, " +
|
||||||
|
"d50, sigma, critical_constraint, sl) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {ind}, '{self._sql_format(self._name)}', " +
|
f"{self.id}, {ind}, '{self._db_format(self._name)}', " +
|
||||||
f"'{self._sql_format(self._type)}', {self._height}, " +
|
f"'{self._db_format(self._type)}', {self._height}, " +
|
||||||
f"{self._d50}, {self._sigma}, {self._critical_constraint}, " +
|
f"{self._d50}, {self._sigma}, {self._critical_constraint}, " +
|
||||||
f"{sl.id}" +
|
f"{sl.id}" +
|
||||||
")"
|
")"
|
||||||
@@ -162,9 +165,9 @@ class SedimentLayer(SQLSubModel):
|
|||||||
_sub_classes = [Layer]
|
_sub_classes = [Layer]
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
|
|
||||||
def __init__(self, id:int = -1,
|
def __init__(self, id: int = -1,
|
||||||
name:str = "", comment:str = "",
|
name: str = "", comment: str = "",
|
||||||
status = None):
|
status=None):
|
||||||
super(SedimentLayer, self).__init__()
|
super(SedimentLayer, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
@@ -196,7 +199,7 @@ class SedimentLayer(SQLSubModel):
|
|||||||
|
|
||||||
def height(self):
|
def height(self):
|
||||||
return list(
|
return list(
|
||||||
map(lambda l: l.height, self._layers)
|
map(lambda layer: layer.height, self._layers)
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -209,7 +212,7 @@ class SedimentLayer(SQLSubModel):
|
|||||||
|
|
||||||
def names(self):
|
def names(self):
|
||||||
return list(
|
return list(
|
||||||
map(lambda l: l.name, self._layers)
|
map(lambda layer: layer.name, self._layers)
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -221,7 +224,7 @@ class SedimentLayer(SQLSubModel):
|
|||||||
self._comment = comment
|
self._comment = comment
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE sedimentary_layer(
|
CREATE TABLE sedimentary_layer(
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
@@ -233,16 +236,16 @@ class SedimentLayer(SQLSubModel):
|
|||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
if major == minor == "0":
|
if major == minor == "0":
|
||||||
if int(release) < 2:
|
if int(release) < 2:
|
||||||
cls._sql_create(execute)
|
cls._db_create(execute)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
@@ -252,36 +255,36 @@ class SedimentLayer(SQLSubModel):
|
|||||||
|
|
||||||
for row in table:
|
for row in table:
|
||||||
sl = cls(
|
sl = cls(
|
||||||
id = row[0],
|
id=row[0],
|
||||||
name = row[1],
|
name=row[1],
|
||||||
comment = row[2],
|
comment=row[2],
|
||||||
status = data['status']
|
status=data['status']
|
||||||
)
|
)
|
||||||
|
|
||||||
data["sl"] = sl.id
|
data["sl"] = sl.id
|
||||||
sl._layers = Layer._sql_load(execute, data)
|
sl._layers = Layer._db_load(execute, data)
|
||||||
|
|
||||||
new.append(sl)
|
new.append(sl)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
if data is None:
|
if data is None:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO sedimentary_layer (id, name, comment) " +
|
"INSERT INTO sedimentary_layer (id, name, comment) " +
|
||||||
f"VALUES ({self.id}, '{self._sql_format(self._name)}', " +
|
f"VALUES ({self.id}, '{self._db_format(self._name)}', " +
|
||||||
f"'{self._sql_format(self._comment)}')"
|
f"'{self._db_format(self._comment)}')"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
|
|
||||||
data["sl"] = self
|
data["sl"] = self
|
||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
for l in self._layers:
|
for layer in self._layers:
|
||||||
data["ind"] = ind
|
data["ind"] = ind
|
||||||
l._sql_save(execute, data)
|
layer._db_save(execute, data)
|
||||||
ind += 1
|
ind += 1
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@@ -298,7 +301,7 @@ class SedimentLayer(SQLSubModel):
|
|||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def new(self, index):
|
def new(self, index):
|
||||||
n = Layer(sl=self, status = self._status)
|
n = Layer(sl=self, status=self._status)
|
||||||
self.insert(index, n)
|
self.insert(index, n)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return n
|
return n
|
||||||
@@ -324,8 +327,8 @@ class SedimentLayer(SQLSubModel):
|
|||||||
if index >= 0:
|
if index >= 0:
|
||||||
next = index - 1
|
next = index - 1
|
||||||
|
|
||||||
l = self._layers
|
lst = self._layers
|
||||||
l[index], l[next] = l[next], l[index]
|
lst[index], lst[next] = lst[next], lst[index]
|
||||||
|
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
@@ -333,7 +336,7 @@ class SedimentLayer(SQLSubModel):
|
|||||||
if index + 1 < len(self._layers):
|
if index + 1 < len(self._layers):
|
||||||
prev = index + 1
|
prev = index + 1
|
||||||
|
|
||||||
l = self._layers
|
lst = self._layers
|
||||||
l[index], l[prev] = l[prev], l[index]
|
lst[index], lst[prev] = lst[prev], lst[index]
|
||||||
|
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
@@ -2,100 +2,40 @@
|
|||||||
|
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
from Model.Tools.PamhyrList import PamhyrModelList
|
||||||
from Model.SedimentLayer.SedimentLayer import SedimentLayer
|
from Model.SedimentLayer.SedimentLayer import SedimentLayer
|
||||||
|
|
||||||
class SedimentLayerList(SQLSubModel):
|
|
||||||
|
class SedimentLayerList(PamhyrModelList):
|
||||||
_sub_classes = [SedimentLayer]
|
_sub_classes = [SedimentLayer]
|
||||||
|
|
||||||
def __init__(self, status = None):
|
|
||||||
super(SedimentLayerList, self).__init__()
|
|
||||||
|
|
||||||
self._status = status
|
|
||||||
self._sl = []
|
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
return len(self._sl)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_load(cls, execute, data=None):
|
||||||
return cls._create_submodel(execute)
|
new = cls(status=data["status"])
|
||||||
|
|
||||||
@classmethod
|
new._lst = SedimentLayer._db_load(execute, data)
|
||||||
def _sql_update(cls, execute, version):
|
|
||||||
return cls._update_submodel(execute, version)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _sql_load(cls, execute, data = None):
|
|
||||||
new = cls(status = data["status"])
|
|
||||||
|
|
||||||
new._sl = SedimentLayer._sql_load(execute, data)
|
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
ok = True
|
ok = True
|
||||||
|
|
||||||
# Delete previous data
|
# Delete previous data
|
||||||
execute("DELETE FROM sedimentary_layer")
|
execute("DELETE FROM sedimentary_layer")
|
||||||
execute("DELETE FROM sedimentary_layer_layer")
|
execute("DELETE FROM sedimentary_layer_layer")
|
||||||
|
|
||||||
for sl in self._sl:
|
for sl in self._lst:
|
||||||
ok &= sl._sql_save(execute, data)
|
ok &= sl._db_save(execute, data)
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sediment_layers(self):
|
def sediment_layers(self):
|
||||||
return self._sl.copy()
|
return self.lst
|
||||||
|
|
||||||
def get(self, index):
|
|
||||||
return self._sl[index]
|
|
||||||
|
|
||||||
def set(self, index, new):
|
|
||||||
self._sl[index] = new
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def insert(self, index, new):
|
|
||||||
self._sl.insert(index, new)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def new(self, index):
|
def new(self, index):
|
||||||
n = SedimentLayer(status = self._status)
|
n = SedimentLayer(status=self._status)
|
||||||
self.insert(index, n)
|
self.insert(index, n)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def delete(self, els):
|
|
||||||
for el in els:
|
|
||||||
self._sl.remove(el)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def delete_i(self, indexes):
|
|
||||||
els = list(
|
|
||||||
map(
|
|
||||||
lambda x: x[1],
|
|
||||||
filter(
|
|
||||||
lambda x: x[0] in indexes,
|
|
||||||
enumerate(self._sl)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.delete(els)
|
|
||||||
|
|
||||||
def move_up(self, index):
|
|
||||||
if index < len(self._sl):
|
|
||||||
next = index - 1
|
|
||||||
|
|
||||||
l = self._sl
|
|
||||||
l[index], l[next] = l[next], l[index]
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def move_down(self, index):
|
|
||||||
if index >= 0:
|
|
||||||
prev = index + 1
|
|
||||||
|
|
||||||
l = self._sl
|
|
||||||
l[index], l[prev] = l[prev], l[index]
|
|
||||||
self._status.modified()
|
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
|
||||||
class Serializable():
|
class Serializable():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -20,12 +20,13 @@ from copy import copy
|
|||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
from Solver.Solvers import solver_type_list
|
from Solver.Solvers import solver_type_list
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrList import PamhyrModelList
|
||||||
|
|
||||||
|
|
||||||
class Parameter():
|
class Parameter():
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
name = "", value = "",
|
name="", value="",
|
||||||
status = None):
|
status=None):
|
||||||
self._status = status
|
self._status = status
|
||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
@@ -57,28 +58,28 @@ class Parameter():
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_tuple(cls, data, status):
|
def from_tuple(cls, data, status):
|
||||||
new = cls(status = status)
|
new = cls(status=status)
|
||||||
new["name"] = data[0]
|
new["name"] = data[0]
|
||||||
new["value"] = data[1]
|
new["value"] = data[1]
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
class SolverParametersList(SQLSubModel):
|
|
||||||
def __init__(self, solver_type = None, status = None):
|
class SolverParametersList(PamhyrModelList):
|
||||||
|
def __init__(self, solver_type=None, status=None):
|
||||||
super(SolverParametersList, self).__init__()
|
super(SolverParametersList, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
self._solver = solver_type
|
self._solver = solver_type
|
||||||
self._parameters = list(
|
self._lst = list(
|
||||||
map(
|
map(
|
||||||
lambda t: Parameter.from_tuple(t, self._status),
|
lambda t: Parameter.from_tuple(t, self._status),
|
||||||
solver_type.default_parameters()
|
solver_type.default_parameters()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE solver_parameter(
|
CREATE TABLE solver_parameter(
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -92,40 +93,47 @@ class SolverParametersList(SQLSubModel):
|
|||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
|
|
||||||
if major == minor == "0":
|
if major == minor == "0":
|
||||||
if int(release) < 3:
|
if int(release) < 3:
|
||||||
execute(f"UPDATE solver_parameter SET name='mage_implicitation' WHERE name='mage_implication'")
|
execute(
|
||||||
execute(f"UPDATE solver_parameter SET name='mage_iteration_type' WHERE name='mage_iter_type'")
|
"UPDATE solver_parameter SET name='mage_implicitation' " +
|
||||||
|
"WHERE name='mage_implication'"
|
||||||
|
)
|
||||||
|
execute(
|
||||||
|
"UPDATE solver_parameter SET name='mage_iteration_type' " +
|
||||||
|
"WHERE name='mage_iter_type'"
|
||||||
|
)
|
||||||
|
|
||||||
if int(release) < 4:
|
if int(release) < 4:
|
||||||
solvers = execute("SELECT DISTINCT solver FROM solver_parameter")
|
solvers = execute(
|
||||||
|
"SELECT DISTINCT solver FROM solver_parameter")
|
||||||
|
|
||||||
for solver in solvers:
|
for solver in solvers:
|
||||||
if solver != "mage8":
|
if solver != "mage8":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
data = execute("SELECT ind, name, value " +
|
data = execute("SELECT ind, name, value " +
|
||||||
"FROM solver_parameter "+
|
"FROM solver_parameter " +
|
||||||
f"WHERE solver = '{solver}' " +
|
f"WHERE solver = '{solver}' " +
|
||||||
"ORDER BY ind ACS")
|
"ORDER BY ind ACS")
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"DELETE FROM solver_parameter " +
|
"DELETE FROM solver_parameter " +
|
||||||
f"WHERE solver = '{solver}'"
|
f"WHERE solver = '{solver}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
insert = lambda name, value, ind: execute(
|
def insert(name, value, ind): return execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"solver_parameter(ind, name, value, solver) "+
|
"solver_parameter(ind, name, value, solver) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{ind}, " +
|
f"{ind}, " +
|
||||||
f"'{cls._sql_format(name)}', " +
|
f"'{cls._db_format(name)}', " +
|
||||||
f"'{cls._sql_format(value)}', " +
|
f"'{cls._db_format(value)}', " +
|
||||||
f"'{cls._sql_format(solver)}'" +
|
f"'{cls._db_format(solver)}'" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
@@ -156,7 +164,7 @@ class SolverParametersList(SQLSubModel):
|
|||||||
return cls._update_submodel(execute, version)
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
status = data["status"]
|
status = data["status"]
|
||||||
solvers = execute("SELECT DISTINCT solver FROM solver_parameter")
|
solvers = execute("SELECT DISTINCT solver FROM solver_parameter")
|
||||||
new = {}
|
new = {}
|
||||||
@@ -167,7 +175,7 @@ class SolverParametersList(SQLSubModel):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
st = solver_type_list[solver]
|
st = solver_type_list[solver]
|
||||||
n = cls(solver_type = st, status = status)
|
n = cls(solver_type=st, status=status)
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT ind, name, value " +
|
"SELECT ind, name, value " +
|
||||||
@@ -186,7 +194,7 @@ class SolverParametersList(SQLSubModel):
|
|||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
t = self._solver._type
|
t = self._solver._type
|
||||||
execute(
|
execute(
|
||||||
"DELETE FROM solver_parameter " +
|
"DELETE FROM solver_parameter " +
|
||||||
@@ -194,15 +202,15 @@ class SolverParametersList(SQLSubModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ind = 0
|
ind = 0
|
||||||
for param in self._parameters:
|
for param in self._lst:
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"solver_parameter(ind, name, value, solver) "+
|
"solver_parameter(ind, name, value, solver) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{ind}, " +
|
f"{ind}, " +
|
||||||
f"'{self._sql_format(param.name)}', " +
|
f"'{self._db_format(param.name)}', " +
|
||||||
f"'{self._sql_format(param.value)}', " +
|
f"'{self._db_format(param.value)}', " +
|
||||||
f"'{self._sql_format(t)}'" +
|
f"'{self._db_format(t)}'" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
execute(sql)
|
||||||
@@ -210,90 +218,46 @@ class SolverParametersList(SQLSubModel):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
return len(self._parameters)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parameters(self):
|
def parameters(self):
|
||||||
return self._parameters.copy()
|
return self.lst
|
||||||
|
|
||||||
def get(self, index):
|
def get(self, index):
|
||||||
return self._parameters[index]
|
return self._lst[index]
|
||||||
|
|
||||||
def get_by_key(self, key):
|
def get_by_key(self, key):
|
||||||
try:
|
try:
|
||||||
return next(
|
return next(
|
||||||
filter(
|
filter(
|
||||||
lambda p: p["name"] == key,
|
lambda p: p["name"] == key,
|
||||||
self._parameters
|
self._lst
|
||||||
)
|
)
|
||||||
)["value"]
|
)["value"]
|
||||||
except:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def set(self, index, new):
|
def set(self, index, new):
|
||||||
self._parameters[index] = new
|
self._lst[index] = new
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def set_value(self, key, value):
|
def set_value(self, key, value):
|
||||||
for p in self._parameters:
|
for p in self._lst:
|
||||||
if p["name"] == key:
|
if p["name"] == key:
|
||||||
p["value"] = value
|
p["value"] = value
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return
|
return
|
||||||
|
|
||||||
self._parameters.append(
|
self._lst.append(
|
||||||
Parameter(
|
Parameter(
|
||||||
name = key,
|
name=key,
|
||||||
value = value,
|
value=value,
|
||||||
status = self._status
|
status=self._status
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
|
|
||||||
def new(self, index):
|
def new(self, index):
|
||||||
n = Parameter(status = self._status)
|
n = Parameter(status=self._status)
|
||||||
self._parameters.insert(index, n)
|
self._lst.insert(index, n)
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def insert(self, index, new):
|
|
||||||
self._parameters.insert(index, new)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def delete(self, parameters):
|
|
||||||
for parameter in parameters:
|
|
||||||
self._parameters.remove(parameter)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def delete_i(self, indexes):
|
|
||||||
parameters = list(
|
|
||||||
map(
|
|
||||||
lambda x: x[1],
|
|
||||||
filter(
|
|
||||||
lambda x: x[0] in indexes,
|
|
||||||
enumerate(self._parameters)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.delete(parameters)
|
|
||||||
|
|
||||||
def sort(self, reverse=False, key=None):
|
|
||||||
self._parameters.sort(reverse=reverse, key=key)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def move_up(self, index):
|
|
||||||
if index < len(self._parameters):
|
|
||||||
next = index - 1
|
|
||||||
|
|
||||||
l = self._parameters
|
|
||||||
l[index], l[next] = l[next], l[index]
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def move_down(self, index):
|
|
||||||
if index >= 0:
|
|
||||||
prev = index + 1
|
|
||||||
|
|
||||||
l = self._parameters
|
|
||||||
l[index], l[prev] = l[prev], l[index]
|
|
||||||
self._status.modified()
|
|
||||||
@@ -18,18 +18,19 @@
|
|||||||
|
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
|
||||||
|
|
||||||
class Stricklers(SQLSubModel):
|
class Stricklers(SQLSubModel):
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
|
|
||||||
def __init__(self, id:int = -1,
|
def __init__(self, id: int = -1,
|
||||||
name:str = "",
|
name: str = "",
|
||||||
comment:str = "",
|
comment: str = "",
|
||||||
minor:float = 35.0,
|
minor: float = 35.0,
|
||||||
medium:float = 15.0,
|
medium: float = 15.0,
|
||||||
status = None):
|
status=None):
|
||||||
super(Stricklers, self).__init__()
|
super(Stricklers, self).__init__()
|
||||||
self._status = status
|
self._status = status
|
||||||
|
|
||||||
@@ -46,9 +47,8 @@ class Stricklers(SQLSubModel):
|
|||||||
self._minor = minor
|
self._minor = minor
|
||||||
self._medium = medium
|
self._medium = medium
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
execute("""
|
execute("""
|
||||||
CREATE TABLE stricklers(
|
CREATE TABLE stricklers(
|
||||||
id INTEGER NOT NULL PRIMARY KEY,
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
@@ -62,11 +62,11 @@ class Stricklers(SQLSubModel):
|
|||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
return cls._update_submodel(execute, version)
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
stricklers = []
|
stricklers = []
|
||||||
status = data["status"]
|
status = data["status"]
|
||||||
|
|
||||||
@@ -86,25 +86,25 @@ class Stricklers(SQLSubModel):
|
|||||||
medium = row[4]
|
medium = row[4]
|
||||||
|
|
||||||
new = cls(
|
new = cls(
|
||||||
id = id,
|
id=id,
|
||||||
name = name,
|
name=name,
|
||||||
comment = comment,
|
comment=comment,
|
||||||
minor = minor, medium = medium,
|
minor=minor, medium=medium,
|
||||||
status = status
|
status=status
|
||||||
)
|
)
|
||||||
|
|
||||||
stricklers.append(new)
|
stricklers.append(new)
|
||||||
|
|
||||||
return stricklers
|
return stricklers
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
sql = (
|
sql = (
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"stricklers(id, name, comment, minor, medium) "+
|
"stricklers(id, name, comment, minor, medium) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, " +
|
f"{self.id}, " +
|
||||||
f"'{self._sql_format(self.name)}', " +
|
f"'{self._db_format(self.name)}', " +
|
||||||
f"'{self._sql_format(self.comment)}', " +
|
f"'{self._db_format(self.comment)}', " +
|
||||||
f"{float(self.minor)}, {float(self.medium)}" +
|
f"{float(self.minor)}, {float(self.medium)}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -18,99 +18,61 @@
|
|||||||
|
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.DB import SQLSubModel
|
|
||||||
from Model.Saved import SavedStatus
|
from Model.Saved import SavedStatus
|
||||||
|
from Model.Tools.PamhyrList import PamhyrModelList
|
||||||
from Model.Stricklers.Stricklers import Stricklers
|
from Model.Stricklers.Stricklers import Stricklers
|
||||||
|
|
||||||
class StricklersList(SQLSubModel):
|
|
||||||
|
class StricklersList(PamhyrModelList):
|
||||||
_sub_classes = [
|
_sub_classes = [
|
||||||
Stricklers,
|
Stricklers,
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, status = None):
|
|
||||||
if status is None:
|
|
||||||
status = SavedStatus()
|
|
||||||
self._status = status
|
|
||||||
|
|
||||||
self._stricks = []
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
return cls._update_submodel(execute, version)
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = cls(status = data["status"])
|
new = cls(status=data["status"])
|
||||||
|
|
||||||
new._stricks = Stricklers._sql_load(
|
new._lst = Stricklers._db_load(
|
||||||
execute,
|
execute,
|
||||||
data = data
|
data=data
|
||||||
)
|
)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
execute("DELETE FROM stricklers")
|
execute("DELETE FROM stricklers")
|
||||||
|
|
||||||
objs = self._stricks
|
objs = self._lst
|
||||||
return self._save_submodel(execute, objs, data)
|
return self._save_submodel(execute, objs, data)
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
return len(self._stricks)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def stricklers(self):
|
def stricklers(self):
|
||||||
return self._stricks.copy()
|
return self.lst
|
||||||
|
|
||||||
def get(self, index):
|
def new(self, index):
|
||||||
if 0 <= index < len(self._stricks):
|
s = Stricklers(status=self._status)
|
||||||
return self._stricks[index]
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
def insert(self, index, strick):
|
|
||||||
self._stricks.insert(index, strick)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def add(self, index):
|
|
||||||
s = Stricklers(status = self._status)
|
|
||||||
self.insert(index, s)
|
self.insert(index, s)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def delete(self, stricks):
|
|
||||||
self._stricks = list(
|
|
||||||
filter(
|
|
||||||
lambda s: s not in stricks,
|
|
||||||
self._stricks
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self._status.modified()
|
|
||||||
|
|
||||||
def delete_i(self, indexes):
|
|
||||||
stricks = set(
|
|
||||||
map(
|
|
||||||
lambda e: e[1],
|
|
||||||
filter(
|
|
||||||
lambda e: e[0] in indexes,
|
|
||||||
enumerate(self._stricks)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.delete(stricks)
|
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def sort(self, reverse:bool = False, key=None):
|
def sort(self, reverse: bool = False, key=None):
|
||||||
f = lambda st: st.name
|
def f(st): return st.name
|
||||||
if key is not None:
|
if key is not None:
|
||||||
f = key
|
f = key
|
||||||
|
|
||||||
self._stricks = sorted(
|
self._lst = sorted(
|
||||||
self._stricks,
|
self._lst,
|
||||||
key = f,
|
key=f,
|
||||||
reverse = reverse,
|
reverse=reverse,
|
||||||
)
|
)
|
||||||
self._status.modified()
|
|
||||||
|
if self._status is not None:
|
||||||
|
self._status.modified()
|
||||||
@@ -23,7 +23,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from tools import timer, timestamp
|
from tools import timer, timestamp
|
||||||
|
|
||||||
from Model.DB import SQLModel
|
from Model.Tools.PamhyrDB import SQLModel
|
||||||
from Model.Saved import SavedStatus
|
from Model.Saved import SavedStatus
|
||||||
from Model.Serializable import Serializable
|
from Model.Serializable import Serializable
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
@@ -33,20 +33,21 @@ from Checker.Study import *
|
|||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class Study(SQLModel):
|
class Study(SQLModel):
|
||||||
_sub_classes = [
|
_sub_classes = [
|
||||||
River,
|
River,
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, filename = None, init_new = True):
|
def __init__(self, filename=None, init_new=True):
|
||||||
# Metadata
|
# Metadata
|
||||||
self._version = "0.0.4"
|
self._version = "0.0.5"
|
||||||
self.creation_date = datetime.now()
|
self.creation_date = datetime.now()
|
||||||
self.last_modification_date = datetime.now()
|
self.last_modification_date = datetime.now()
|
||||||
self.last_save_date = datetime.now()
|
self.last_save_date = datetime.now()
|
||||||
|
|
||||||
self._filename = filename
|
self._filename = filename
|
||||||
super(Study, self).__init__(filename = filename)
|
super(Study, self).__init__(filename=filename)
|
||||||
|
|
||||||
self.status = SavedStatus()
|
self.status = SavedStatus()
|
||||||
|
|
||||||
@@ -59,9 +60,9 @@ class Study(SQLModel):
|
|||||||
|
|
||||||
if init_new:
|
if init_new:
|
||||||
# Study data
|
# Study data
|
||||||
self._river = River(status = self.status)
|
self._river = River(status=self.status)
|
||||||
else:
|
else:
|
||||||
self._init_db_file(filename, is_new = False)
|
self._init_db_file(filename, is_new=False)
|
||||||
|
|
||||||
self._old_save_id = 0
|
self._old_save_id = 0
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ class Study(SQLModel):
|
|||||||
@filename.setter
|
@filename.setter
|
||||||
def filename(self, filename):
|
def filename(self, filename):
|
||||||
self._filename = str(filename)
|
self._filename = str(filename)
|
||||||
self._init_db_file(filename, is_new = True)
|
self._init_db_file(filename, is_new=True)
|
||||||
self.status.modified()
|
self.status.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -139,7 +140,7 @@ class Study(SQLModel):
|
|||||||
self._time_system = "time"
|
self._time_system = "time"
|
||||||
self.status.modified()
|
self.status.modified()
|
||||||
|
|
||||||
def use_date(self, date:datetime):
|
def use_date(self, date: datetime):
|
||||||
self._time_system = "date"
|
self._time_system = "date"
|
||||||
self._date = date
|
self._date = date
|
||||||
self.status.modified()
|
self.status.modified()
|
||||||
@@ -158,7 +159,7 @@ class Study(SQLModel):
|
|||||||
# return cls()
|
# return cls()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new(cls, name, description, date = None):
|
def new(cls, name, description, date=None):
|
||||||
me = cls()
|
me = cls()
|
||||||
me.name = name
|
me.name = name
|
||||||
me.description = description
|
me.description = description
|
||||||
@@ -176,16 +177,26 @@ class Study(SQLModel):
|
|||||||
# SQL #
|
# SQL #
|
||||||
#######
|
#######
|
||||||
|
|
||||||
|
def _db_insert_into_info(self, key, value, commit=False):
|
||||||
|
self.execute(
|
||||||
|
"INSERT INTO info VALUES " +
|
||||||
|
f"('{key}', '{self._db_format(value)}')",
|
||||||
|
commit=commit
|
||||||
|
)
|
||||||
|
|
||||||
def _create(self):
|
def _create(self):
|
||||||
# Info (metadata)
|
# Info (metadata)
|
||||||
self.execute("CREATE TABLE info(key TEXT NOT NULL UNIQUE, value TEXT NOT NULL)")
|
|
||||||
self.execute(
|
self.execute(
|
||||||
f"INSERT INTO info VALUES ('version', '{self._sql_format(self._version)}')",
|
"CREATE TABLE info(key TEXT NOT NULL UNIQUE, value TEXT NOT NULL)")
|
||||||
commit = True
|
self.execute(
|
||||||
|
"INSERT INTO info VALUES ('version', " +
|
||||||
|
f"'{self._db_format(self._version)}')",
|
||||||
|
commit=True
|
||||||
)
|
)
|
||||||
self.execute("INSERT INTO info VALUES ('name', '')")
|
self.execute("INSERT INTO info VALUES ('name', '')")
|
||||||
self.execute("INSERT INTO info VALUES ('description', '')")
|
self.execute("INSERT INTO info VALUES ('description', '')")
|
||||||
self.execute(f"INSERT INTO info VALUES ('time_system', '{self._time_system}')")
|
self.execute(
|
||||||
|
f"INSERT INTO info VALUES ('time_system', '{self._time_system}')")
|
||||||
self.execute(
|
self.execute(
|
||||||
f"INSERT INTO info VALUES ('date', " +
|
f"INSERT INTO info VALUES ('date', " +
|
||||||
"'{self._date.timestamp()}')"
|
"'{self._date.timestamp()}')"
|
||||||
@@ -213,7 +224,8 @@ class Study(SQLModel):
|
|||||||
logger.info("Update database")
|
logger.info("Update database")
|
||||||
|
|
||||||
if self._update_submodel(version[0]):
|
if self._update_submodel(version[0]):
|
||||||
self.execute(f"UPDATE info SET value='{self._version}' WHERE key='version'")
|
self.execute(
|
||||||
|
f"UPDATE info SET value='{self._version}' WHERE key='version'")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
logger.info("TODO: update failed")
|
logger.info("TODO: update failed")
|
||||||
@@ -221,42 +233,75 @@ class Study(SQLModel):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _load(cls, filename):
|
def _load(cls, filename):
|
||||||
new = cls(init_new = False, filename = filename)
|
new = cls(init_new=False, filename=filename)
|
||||||
|
|
||||||
# TODO: Load metadata
|
# TODO: Load metadata
|
||||||
new.name = new.execute("SELECT value FROM info WHERE key='name'")[0]
|
new.name = new.execute("SELECT value FROM info WHERE key='name'")[0]
|
||||||
new.description = new.execute("SELECT value FROM info WHERE key='description'")[0]
|
new.description = new.execute(
|
||||||
new._time_system = new.execute("SELECT value FROM info WHERE key='time_system'")[0]
|
"SELECT value FROM info WHERE key='description'")[0]
|
||||||
|
new._time_system = new.execute(
|
||||||
|
"SELECT value FROM info WHERE key='time_system'")[0]
|
||||||
new._date = datetime.fromtimestamp(
|
new._date = datetime.fromtimestamp(
|
||||||
float(new.execute("SELECT value FROM info WHERE key='date'")[0])
|
float(new.execute("SELECT value FROM info WHERE key='date'")[0])
|
||||||
)
|
)
|
||||||
|
|
||||||
new.creation_date = datetime.fromtimestamp(
|
new.creation_date = datetime.fromtimestamp(
|
||||||
float(new.execute("SELECT value FROM info WHERE key='creation_date'")[0])
|
float(new.execute(
|
||||||
|
"SELECT value FROM info WHERE key='creation_date'")[0])
|
||||||
)
|
)
|
||||||
new.last_save_date = datetime.fromtimestamp(
|
new.last_save_date = datetime.fromtimestamp(
|
||||||
float(new.execute("SELECT value FROM info WHERE key='last_save_date'")[0])
|
float(new.execute(
|
||||||
|
"SELECT value FROM info WHERE key='last_save_date'")[0])
|
||||||
)
|
)
|
||||||
|
|
||||||
# Load river data
|
# Load river data
|
||||||
new._river = River._sql_load(
|
new._river = River._db_load(
|
||||||
lambda sql: new.execute(
|
lambda sql: new.execute(
|
||||||
sql,
|
sql,
|
||||||
fetch_one = False,
|
fetch_one=False,
|
||||||
commit = True
|
commit=True
|
||||||
),
|
),
|
||||||
data = {"status": new.status}
|
data={"status": new.status}
|
||||||
)
|
)
|
||||||
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def _save(self):
|
def _save(self):
|
||||||
self.execute(f"UPDATE info SET value='{self._sql_format(self.name)}' WHERE key='name'")
|
self.execute(
|
||||||
self.execute(f"UPDATE info SET value='{self._sql_format(self.description)}' WHERE key='description'")
|
f"UPDATE info SET " +
|
||||||
self.execute(f"UPDATE info SET value='{self._time_system}' WHERE key='time_system'")
|
f"value='{self._db_format(self.name)}' WHERE key='name'"
|
||||||
self.execute(f"UPDATE info SET value='{timestamp(self._date)}' WHERE key='date'")
|
)
|
||||||
self.execute(f"UPDATE info SET value='{timestamp(self.creation_date)}' WHERE key='creation_date'")
|
self.execute(
|
||||||
self.execute(f"UPDATE info SET value='{timestamp(self.last_save_date)}' WHERE key='last_save_date'")
|
f"UPDATE info SET " +
|
||||||
|
f"value='{self._db_format(self.description)}' " +
|
||||||
|
"WHERE key='description'"
|
||||||
|
)
|
||||||
|
self.execute(
|
||||||
|
f"UPDATE info SET " +
|
||||||
|
f"value='{self._time_system}' WHERE key='time_system'"
|
||||||
|
)
|
||||||
|
self.execute(
|
||||||
|
f"UPDATE info SET " +
|
||||||
|
f"value='{timestamp(self._date)}' WHERE key='date'"
|
||||||
|
)
|
||||||
|
self.execute(
|
||||||
|
f"UPDATE info SET " +
|
||||||
|
f"value='{timestamp(self.creation_date)}' " +
|
||||||
|
"WHERE key='creation_date'"
|
||||||
|
)
|
||||||
|
self.execute(
|
||||||
|
f"UPDATE info SET " +
|
||||||
|
f"value='{timestamp(self.last_save_date)}' " +
|
||||||
|
"WHERE key='last_save_date'"
|
||||||
|
)
|
||||||
|
|
||||||
self._save_submodel([self._river])
|
self._save_submodel([self._river])
|
||||||
self.commit()
|
self.commit()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
"""Close db connection
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Nothing.
|
||||||
|
"""
|
||||||
|
self._close()
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# DB.py -- Pamhyr abstract model database classes
|
# PamhyrDB.py -- Pamhyr abstract model database classes
|
||||||
# Copyright (C) 2023 INRAE
|
# Copyright (C) 2023 INRAE
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
@@ -28,10 +28,12 @@ from Model.Except import NotImplementedMethodeError
|
|||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
# Top level model class
|
# Top level model class
|
||||||
|
|
||||||
|
|
||||||
class SQLModel(SQL):
|
class SQLModel(SQL):
|
||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
|
|
||||||
def _init_db_file(self, db, is_new = True):
|
def _init_db_file(self, db, is_new=True):
|
||||||
exists = Path(db).exists()
|
exists = Path(db).exists()
|
||||||
|
|
||||||
if exists and is_new:
|
if exists and is_new:
|
||||||
@@ -48,19 +50,18 @@ class SQLModel(SQL):
|
|||||||
self._update() # Update db scheme if necessary
|
self._update() # Update db scheme if necessary
|
||||||
# self._load() # Load data
|
# self._load() # Load data
|
||||||
|
|
||||||
|
def __init__(self, filename=None):
|
||||||
def __init__(self, filename = None):
|
|
||||||
self._db = None
|
self._db = None
|
||||||
|
|
||||||
def _create_submodel(self):
|
def _create_submodel(self):
|
||||||
fn = lambda sql: self.execute(
|
def fn(sql): return self.execute(
|
||||||
sql,
|
sql,
|
||||||
fetch_one = False,
|
fetch_one=False,
|
||||||
commit = False
|
commit=False
|
||||||
)
|
)
|
||||||
|
|
||||||
for cls in self._sub_classes:
|
for cls in self._sub_classes:
|
||||||
requests = cls._sql_create(fn)
|
requests = cls._db_create(fn)
|
||||||
|
|
||||||
self.commit()
|
self.commit()
|
||||||
return True
|
return True
|
||||||
@@ -69,15 +70,15 @@ class SQLModel(SQL):
|
|||||||
raise NotImplementedMethodeError(self, self._create)
|
raise NotImplementedMethodeError(self, self._create)
|
||||||
|
|
||||||
def _update_submodel(self, version):
|
def _update_submodel(self, version):
|
||||||
fn = lambda sql: self.execute(
|
def fn(sql): return self.execute(
|
||||||
sql,
|
sql,
|
||||||
fetch_one = False,
|
fetch_one=False,
|
||||||
commit = False
|
commit=False
|
||||||
)
|
)
|
||||||
|
|
||||||
ok = True
|
ok = True
|
||||||
for cls in self._sub_classes:
|
for cls in self._sub_classes:
|
||||||
ok &= cls._sql_update(fn, version)
|
ok &= cls._db_update(fn, version)
|
||||||
|
|
||||||
self.commit()
|
self.commit()
|
||||||
return ok
|
return ok
|
||||||
@@ -85,16 +86,16 @@ class SQLModel(SQL):
|
|||||||
def _update(self):
|
def _update(self):
|
||||||
raise NotImplementedMethodeError(self, self._update)
|
raise NotImplementedMethodeError(self, self._update)
|
||||||
|
|
||||||
def _save_submodel(self, objs, data = None):
|
def _save_submodel(self, objs, data=None):
|
||||||
fn = lambda sql: self.execute(
|
def fn(sql): return self.execute(
|
||||||
sql,
|
sql,
|
||||||
fetch_one = False,
|
fetch_one=False,
|
||||||
commit = False
|
commit=False
|
||||||
)
|
)
|
||||||
|
|
||||||
ok = True
|
ok = True
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
ok &= obj._sql_save(fn)
|
ok &= obj._db_save(fn)
|
||||||
|
|
||||||
self.commit()
|
self.commit()
|
||||||
return ok
|
return ok
|
||||||
@@ -103,28 +104,30 @@ class SQLModel(SQL):
|
|||||||
raise NotImplementedMethodeError(self, self._save)
|
raise NotImplementedMethodeError(self, self._save)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _load(cls, filename = None):
|
def _load(cls, filename=None):
|
||||||
raise NotImplementedMethodeError(cls, cls._load)
|
raise NotImplementedMethodeError(cls, cls._load)
|
||||||
|
|
||||||
# Sub model class
|
# Sub model class
|
||||||
|
|
||||||
|
|
||||||
class SQLSubModel(object):
|
class SQLSubModel(object):
|
||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
|
|
||||||
def _sql_format(self, value):
|
def _db_format(self, value):
|
||||||
# Replace ''' by ''' to preserve SQL injection
|
# Replace ''' by ''' to preserve SQL injection
|
||||||
if type(value) == str:
|
if type(value) is str:
|
||||||
value = value.replace("'", "'")
|
value = value.replace("'", "'")
|
||||||
elif type(value) == bool:
|
elif type(value) is bool:
|
||||||
value = 'TRUE' if value else 'FALSE'
|
value = 'TRUE' if value else 'FALSE'
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _create_submodel(cls, execute):
|
def _create_submodel(cls, execute):
|
||||||
for sc in cls._sub_classes:
|
for sc in cls._sub_classes:
|
||||||
sc._sql_create(execute)
|
sc._db_create(execute)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
"""Create data base scheme
|
"""Create data base scheme
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -133,15 +136,15 @@ class SQLSubModel(object):
|
|||||||
Returns:
|
Returns:
|
||||||
Return true, otherelse false if an issue appear
|
Return true, otherelse false if an issue appear
|
||||||
"""
|
"""
|
||||||
raise NotImplementedMethodeError(cls, cls._sql_create)
|
raise NotImplementedMethodeError(cls, cls._db_create)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _update_submodel(cls, execute, version):
|
def _update_submodel(cls, execute, version):
|
||||||
for sc in cls._sub_classes:
|
for sc in cls._sub_classes:
|
||||||
sc._sql_update(execute, version)
|
sc._db_update(execute, version)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_update(cls, execute, version):
|
def _db_update(cls, execute, version):
|
||||||
"""Update data base scheme
|
"""Update data base scheme
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -151,10 +154,10 @@ class SQLSubModel(object):
|
|||||||
Returns:
|
Returns:
|
||||||
Return true, otherelse false if an issue appear
|
Return true, otherelse false if an issue appear
|
||||||
"""
|
"""
|
||||||
raise NotImplementedMethodeError(cls, cls._sql_update)
|
raise NotImplementedMethodeError(cls, cls._db_update)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _sql_load(cls, execute, data = None):
|
def _db_load(cls, execute, data=None):
|
||||||
"""Load instance of this class from SQL data base
|
"""Load instance of this class from SQL data base
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -164,13 +167,13 @@ class SQLSubModel(object):
|
|||||||
Returns:
|
Returns:
|
||||||
Return new instance of class
|
Return new instance of class
|
||||||
"""
|
"""
|
||||||
raise NotImplementedMethodeError(cls, cls._sql_load)
|
raise NotImplementedMethodeError(cls, cls._db_load)
|
||||||
|
|
||||||
def _save_submodel(self, execute, objs, data = None):
|
def _save_submodel(self, execute, objs, data=None):
|
||||||
for o in objs:
|
for o in objs:
|
||||||
o._sql_save(execute, data = data)
|
o._db_save(execute, data=data)
|
||||||
|
|
||||||
def _sql_save(self, execute, data = None):
|
def _db_save(self, execute, data=None):
|
||||||
"""Save class data to data base
|
"""Save class data to data base
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -181,4 +184,4 @@ class SQLSubModel(object):
|
|||||||
Return true, otherelse false if an issue appear during
|
Return true, otherelse false if an issue appear during
|
||||||
save
|
save
|
||||||
"""
|
"""
|
||||||
raise NotImplementedMethodeError(self, self._sql_save)
|
raise NotImplementedMethodeError(self, self._db_save)
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
# PamhyrDict.py -- Pamhyr abstract dict for model classes
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import types
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from copy import copy
|
||||||
|
from tools import trace, timer
|
||||||
|
|
||||||
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class PamhyrModelDict(SQLSubModel):
|
||||||
|
_sub_classes = []
|
||||||
|
|
||||||
|
def __init__(self, status=None):
|
||||||
|
super(PamhyrModelDict, self).__init__()
|
||||||
|
|
||||||
|
self._status = status
|
||||||
|
|
||||||
|
self._dict = {}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_create(cls, execute):
|
||||||
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_update(cls, execute, version):
|
||||||
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_load(cls, execute, data=None):
|
||||||
|
raise NotImplementedMethodeError(cls, cls._db_load)
|
||||||
|
|
||||||
|
def _db_save(self, execute, data=None):
|
||||||
|
raise NotImplementedMethodeError(self, self._db_save)
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self._dict)
|
||||||
|
|
||||||
|
def is_defined(self, key):
|
||||||
|
return key in self._dict
|
||||||
|
|
||||||
|
def set(self, key, new):
|
||||||
|
self._dict[key] = new
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def get(self, key):
|
||||||
|
if key in self._dict:
|
||||||
|
v = self._dict[key]
|
||||||
|
|
||||||
|
if type(v) == types.GeneratorType:
|
||||||
|
return list(v)
|
||||||
|
|
||||||
|
return v
|
||||||
|
|
||||||
|
new = self.new(key)
|
||||||
|
self.set(key, new)
|
||||||
|
return new
|
||||||
|
|
||||||
|
def new(self, key):
|
||||||
|
raise NotImplementedMethodeError(self, self.new)
|
||||||
@@ -0,0 +1,241 @@
|
|||||||
|
# PamhyrList.py -- Pamhyr Abstract List object for the Model
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from copy import copy
|
||||||
|
from tools import trace, timer
|
||||||
|
|
||||||
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class PamhyrModelList(SQLSubModel):
|
||||||
|
_sub_classes = [
|
||||||
|
]
|
||||||
|
|
||||||
|
def __init__(self, status=None):
|
||||||
|
super(PamhyrModelList, self).__init__()
|
||||||
|
|
||||||
|
self._status = status
|
||||||
|
self._lst = []
|
||||||
|
|
||||||
|
#######
|
||||||
|
# SQL #
|
||||||
|
#######
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_create(cls, execute):
|
||||||
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_update(cls, execute, version):
|
||||||
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_load(cls, execute, data=None):
|
||||||
|
raise NotImplementedMethodeError(cls, cls._db_load)
|
||||||
|
|
||||||
|
def _db_save(self, execute, data=None):
|
||||||
|
raise NotImplementedMethodeError(self, self._db_save)
|
||||||
|
|
||||||
|
################
|
||||||
|
# MODEL METHOD #
|
||||||
|
################
|
||||||
|
|
||||||
|
@property
|
||||||
|
def lst(self):
|
||||||
|
return self._lst
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self.lst)
|
||||||
|
|
||||||
|
def get(self, row):
|
||||||
|
return self._lst[row]
|
||||||
|
|
||||||
|
def set(self, row, new):
|
||||||
|
self._lst[row] = new
|
||||||
|
if self._status is not None:
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def new(self, index):
|
||||||
|
"""Create new elements and add it to list
|
||||||
|
|
||||||
|
Args:
|
||||||
|
index: The index of new elements
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The new elements
|
||||||
|
"""
|
||||||
|
raise NotImplementedMethodeError(self, self.new)
|
||||||
|
|
||||||
|
def insert(self, index, new):
|
||||||
|
self._lst.insert(index, new)
|
||||||
|
|
||||||
|
if self._status is not None:
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def delete(self, lst):
|
||||||
|
for el in lst:
|
||||||
|
self._lst.remove(el)
|
||||||
|
|
||||||
|
if self._status is not None:
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def delete_i(self, indexes):
|
||||||
|
lst = list(
|
||||||
|
map(
|
||||||
|
lambda x: x[1],
|
||||||
|
filter(
|
||||||
|
lambda x: x[0] in indexes,
|
||||||
|
enumerate(self._lst)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.delete(lst)
|
||||||
|
|
||||||
|
def sort(self, reverse=False, key=None):
|
||||||
|
self._lst.sort(reverse=reverse, key=key)
|
||||||
|
|
||||||
|
if self._status is not None:
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def move_up(self, index):
|
||||||
|
if index < len(self._lst):
|
||||||
|
next = index - 1
|
||||||
|
|
||||||
|
lst = self._lst
|
||||||
|
lst[index], lst[next] = lst[next], lst[index]
|
||||||
|
|
||||||
|
if self._status is not None:
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def move_down(self, index):
|
||||||
|
if index >= 0:
|
||||||
|
prev = index + 1
|
||||||
|
|
||||||
|
lst = self._lst
|
||||||
|
lst[index], lst[prev] = lst[prev], lst[index]
|
||||||
|
|
||||||
|
if self._status is not None:
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
|
||||||
|
class PamhyrModelListWithTab(SQLSubModel):
|
||||||
|
_tabs_list = []
|
||||||
|
_sub_classes = [
|
||||||
|
]
|
||||||
|
|
||||||
|
def __init__(self, status=None):
|
||||||
|
super(PamhyrModelListWithTab, self).__init__()
|
||||||
|
|
||||||
|
self._status = status
|
||||||
|
self._tabs = {}
|
||||||
|
for tab in self._tabs_list:
|
||||||
|
self._tabs[tab] = []
|
||||||
|
|
||||||
|
#######
|
||||||
|
# SQL #
|
||||||
|
#######
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_create(cls, execute):
|
||||||
|
return cls._create_submodel(execute)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_update(cls, execute, version):
|
||||||
|
return cls._update_submodel(execute, version)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_load(cls, execute, data=None):
|
||||||
|
raise NotImplementedMethodeError(cls, cls._db_load)
|
||||||
|
|
||||||
|
def _db_save(self, execute, data=None):
|
||||||
|
raise NotImplementedMethodeError(self, self._db_save)
|
||||||
|
|
||||||
|
################
|
||||||
|
# MODEL METHOD #
|
||||||
|
################
|
||||||
|
|
||||||
|
def len(self, lst):
|
||||||
|
return len(self._tabs[lst])
|
||||||
|
|
||||||
|
def get_tab(self, lst):
|
||||||
|
return self._tabs[lst].copy()
|
||||||
|
|
||||||
|
def get(self, lst, row):
|
||||||
|
return self._tabs[lst][row]
|
||||||
|
|
||||||
|
def set(self, lst, row, new):
|
||||||
|
self._tabs[lst][row] = new
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def new(self, lst, index):
|
||||||
|
"""Create new elements and add it to list
|
||||||
|
|
||||||
|
Args:
|
||||||
|
lst: The tab name
|
||||||
|
index: The index of new elements
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The new elements
|
||||||
|
"""
|
||||||
|
raise NotImplementedMethodeError(self, self.new)
|
||||||
|
|
||||||
|
def insert(self, lst, index, new):
|
||||||
|
self._tabs[lst].insert(index, new)
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def delete(self, lst, els):
|
||||||
|
for el in els:
|
||||||
|
self._tabs[lst].remove(el)
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def delete_i(self, lst, indexes):
|
||||||
|
els = list(
|
||||||
|
map(
|
||||||
|
lambda x: x[1],
|
||||||
|
filter(
|
||||||
|
lambda x: x[0] in indexes,
|
||||||
|
enumerate(self._tabs[lst])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.delete(lst, els)
|
||||||
|
|
||||||
|
def sort(self, lst, reverse=False, key=None):
|
||||||
|
self._tabs[lst].sort(reverse=reverse, key=key)
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def move_up(self, lst, index):
|
||||||
|
if index < len(self._tabs[lst]):
|
||||||
|
next = index - 1
|
||||||
|
|
||||||
|
lst = self._tabs[lst]
|
||||||
|
lst[index], lst[next] = lst[next], lst[index]
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def move_down(self, lst, index):
|
||||||
|
if index >= 0:
|
||||||
|
prev = index + 1
|
||||||
|
|
||||||
|
lst = self._tabs[lst]
|
||||||
|
lst[index], lst[prev] = lst[prev], lst[index]
|
||||||
|
self._status.modified()
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# __init__.py -- Pamhyr
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
# test_Model.py -- Pamhyr
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from Model.Saved import SavedStatus
|
||||||
|
from Model.Study import Study
|
||||||
|
from Model.River import River
|
||||||
|
|
||||||
|
|
||||||
|
class StudyTestCase(unittest.TestCase):
|
||||||
|
def test_create_study(self):
|
||||||
|
study = Study.new("foo", "bar")
|
||||||
|
self.assertEqual(study.name, "foo")
|
||||||
|
self.assertEqual(study.description, "bar")
|
||||||
|
|
||||||
|
def test_open_study(self):
|
||||||
|
study = Study.open("../tests_cases/Enlargement/Enlargement.pamhyr")
|
||||||
|
self.assertNotEqual(study, None)
|
||||||
|
self.assertEqual(study.name, "Enlargement")
|
||||||
|
|
||||||
|
def test_save_open_study(self):
|
||||||
|
study = Study.new("foo", "bar")
|
||||||
|
dir = tempfile.mkdtemp()
|
||||||
|
f = os.path.join(dir, "foo.pamhyr")
|
||||||
|
|
||||||
|
# Save study
|
||||||
|
study.filename = f
|
||||||
|
study.save()
|
||||||
|
study.close()
|
||||||
|
|
||||||
|
# Reopen study
|
||||||
|
study = Study.open(f)
|
||||||
|
|
||||||
|
# Check
|
||||||
|
self.assertNotEqual(study, None)
|
||||||
|
self.assertEqual(study.name, "foo")
|
||||||
|
self.assertEqual(study.description, "bar")
|
||||||
|
|
||||||
|
def test_create_study_river(self):
|
||||||
|
study = Study.new("foo", "bar")
|
||||||
|
self.assertNotEqual(study.river, None)
|
||||||
|
|
||||||
|
|
||||||
|
class RiverTestCase(unittest.TestCase):
|
||||||
|
def test_create_river(self):
|
||||||
|
status = SavedStatus()
|
||||||
|
river = River(status=status)
|
||||||
|
|
||||||
|
self.assertNotEqual(river, None)
|
||||||
|
|
||||||
|
def test_create_river_nodes(self):
|
||||||
|
status = SavedStatus()
|
||||||
|
river = River(status=status)
|
||||||
|
|
||||||
|
self.assertNotEqual(river, None)
|
||||||
|
|
||||||
|
# Add nodes
|
||||||
|
n0 = river.add_node()
|
||||||
|
n1 = river.add_node(x=1.0, y=0.0)
|
||||||
|
n2 = river.add_node(x=0.0, y=1.0)
|
||||||
|
|
||||||
|
# Checks
|
||||||
|
self.assertEqual(river.nodes_counts(), 3)
|
||||||
|
|
||||||
|
nodes = river.nodes()
|
||||||
|
self.assertEqual(nodes[0], n0)
|
||||||
|
self.assertEqual(nodes[1], n1)
|
||||||
|
self.assertEqual(nodes[2], n2)
|
||||||
|
|
||||||
|
def test_create_river_edges(self):
|
||||||
|
status = SavedStatus()
|
||||||
|
river = River(status=status)
|
||||||
|
|
||||||
|
self.assertNotEqual(river, None)
|
||||||
|
|
||||||
|
# Add nodes
|
||||||
|
n0 = river.add_node()
|
||||||
|
n1 = river.add_node(x=1.0, y=0.0)
|
||||||
|
n2 = river.add_node(x=0.0, y=1.0)
|
||||||
|
|
||||||
|
self.assertEqual(river.nodes_counts(), 3)
|
||||||
|
|
||||||
|
# Add edges
|
||||||
|
e0 = river.add_edge(n0, n1)
|
||||||
|
e1 = river.add_edge(n1, n2)
|
||||||
|
|
||||||
|
# Checks
|
||||||
|
self.assertEqual(river.edges_counts(), 2)
|
||||||
|
|
||||||
|
edges = river.edges()
|
||||||
|
self.assertEqual(edges[0], e0)
|
||||||
|
self.assertEqual(edges[1], e1)
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
# AScript.py -- Pamhyr abstract script class
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
|
|
||||||
|
class AScript(object):
|
||||||
|
name = ""
|
||||||
|
description = ""
|
||||||
|
|
||||||
|
def __init__(self, app, conf, args):
|
||||||
|
super(AScript, self).__init__()
|
||||||
|
|
||||||
|
self._app = app
|
||||||
|
self._conf = conf
|
||||||
|
self._args = args.copy()
|
||||||
|
|
||||||
|
def usage(self):
|
||||||
|
raise NotImplementedMethodeError(self, self.usage)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
raise NotImplementedMethodeError(self, self.run)
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# Hello.py -- Pamhyr
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from Scripts.AScript import AScript
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class ScriptHello(AScript):
|
||||||
|
name = "Hello"
|
||||||
|
description = "Display hello"
|
||||||
|
|
||||||
|
def usage(self):
|
||||||
|
logger.info(f"Usage : {self._args[0]} hello")
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
logger.info("Hello from Pamhyr2 script !")
|
||||||
|
return 0
|
||||||