diff --git a/README.md b/README.md index 4ae172a..10fe544 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,16 @@ Currently available functions accessible via `from pvsite_datamodel.read import Currently available write functions accessible via `from pvsite_datamodels.write import `: - insert_generation_values -- make_user -- make_site -- make_site_group +- create_site +- create_site_group +- create_user +- add_site_to_site_group +- change_user_site_group +- update_user_site_group +- delete_site +- delete_user +- delete_site_group +- make_fake_site ## Install the dependencies (requires [poetry][poetry]) diff --git a/poetry.lock b/poetry.lock index db8328d..fec02cc 100644 --- a/poetry.lock +++ b/poetry.lock @@ -30,6 +30,25 @@ files = [ {file = "annotated_types-0.5.0.tar.gz", hash = "sha256:47cdc3490d9ac1506ce92c7aaa76c579dc3509ff11e098fc867e5130ab7be802"}, ] +[[package]] +name = "attrs" +version = "23.2.0" +description = "Classes Without Boilerplate" +optional = false +python-versions = ">=3.7" +files = [ + {file = "attrs-23.2.0-py3-none-any.whl", hash = "sha256:99b87a485a5820b23b879f04c2305b44b951b502fd64be915879d77a7e8fc6f1"}, + {file = "attrs-23.2.0.tar.gz", hash = "sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30"}, +] + +[package.extras] +cov = ["attrs[tests]", "coverage[toml] (>=5.3)"] +dev = ["attrs[tests]", "pre-commit"] +docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier", "zope-interface"] +tests = ["attrs[tests-no-zope]", "zope-interface"] +tests-mypy = ["mypy (>=1.6)", "pytest-mypy-plugins"] +tests-no-zope = ["attrs[tests-mypy]", "cloudpickle", "hypothesis", "pympler", "pytest (>=4.3.0)", "pytest-xdist[psutil]"] + [[package]] name = "black" version = "23.7.0" @@ -183,6 +202,40 @@ files = [ [package.dependencies] colorama = {version = "*", markers = "platform_system == \"Windows\""} +[[package]] +name = "click-plugins" +version = "1.1.1" +description = "An extension module for click to enable registering CLI commands via setuptools entry-points." +optional = false +python-versions = "*" +files = [ + {file = "click-plugins-1.1.1.tar.gz", hash = "sha256:46ab999744a9d831159c3411bb0c79346d94a444df9a3a3742e9ed63645f264b"}, + {file = "click_plugins-1.1.1-py2.py3-none-any.whl", hash = "sha256:5d262006d3222f5057fd81e1623d4443e41dcda5dc815c06b442aa3c02889fc8"}, +] + +[package.dependencies] +click = ">=4.0" + +[package.extras] +dev = ["coveralls", "pytest (>=3.6)", "pytest-cov", "wheel"] + +[[package]] +name = "cligj" +version = "0.7.2" +description = "Click params for commmand line interfaces to GeoJSON" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4" +files = [ + {file = "cligj-0.7.2-py3-none-any.whl", hash = "sha256:c1ca117dbce1fe20a5809dc96f01e1c2840f6dcc939b3ddbb1111bf330ba82df"}, + {file = "cligj-0.7.2.tar.gz", hash = "sha256:a4bc13d623356b373c2c27c53dbd9c68cae5d526270bfa71f6c6fa69669c6b27"}, +] + +[package.dependencies] +click = ">=4.0" + +[package.extras] +test = ["pytest-cov"] + [[package]] name = "colorama" version = "0.4.6" @@ -293,6 +346,72 @@ websocket-client = ">=0.32.0" [package.extras] ssh = ["paramiko (>=2.4.3)"] +[[package]] +name = "fiona" +version = "1.9.5" +description = "Fiona reads and writes spatial data files" +optional = false +python-versions = ">=3.7" +files = [ + {file = "fiona-1.9.5-cp310-cp310-macosx_10_15_x86_64.whl", hash = "sha256:5f40a40529ecfca5294260316cf987a0420c77a2f0cf0849f529d1afbccd093e"}, + {file = "fiona-1.9.5-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:374efe749143ecb5cfdd79b585d83917d2bf8ecfbfc6953c819586b336ce9c63"}, + {file = "fiona-1.9.5-cp310-cp310-manylinux2014_x86_64.whl", hash = "sha256:35dae4b0308eb44617cdc4461ceb91f891d944fdebbcba5479efe524ec5db8de"}, + {file = "fiona-1.9.5-cp310-cp310-win_amd64.whl", hash = "sha256:5b4c6a3df53bee8f85bb46685562b21b43346be1fe96419f18f70fa1ab8c561c"}, + {file = "fiona-1.9.5-cp311-cp311-macosx_10_15_x86_64.whl", hash = "sha256:6ad04c1877b9fd742871b11965606c6a52f40706f56a48d66a87cc3073943828"}, + {file = "fiona-1.9.5-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:9fb9a24a8046c724787719e20557141b33049466145fc3e665764ac7caf5748c"}, + {file = "fiona-1.9.5-cp311-cp311-manylinux2014_x86_64.whl", hash = "sha256:d722d7f01a66f4ab6cd08d156df3fdb92f0669cf5f8708ddcb209352f416f241"}, + {file = "fiona-1.9.5-cp311-cp311-win_amd64.whl", hash = "sha256:7ede8ddc798f3d447536080c6db9a5fb73733ad8bdb190cb65eed4e289dd4c50"}, + {file = "fiona-1.9.5-cp312-cp312-macosx_10_15_x86_64.whl", hash = "sha256:8b098054a27c12afac4f819f98cb4d4bf2db9853f70b0c588d7d97d26e128c39"}, + {file = "fiona-1.9.5-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:6d9f29e9bcbb33232ff7fa98b4a3c2234db910c1dc6c4147fc36c0b8b930f2e0"}, + {file = "fiona-1.9.5-cp312-cp312-manylinux2014_x86_64.whl", hash = "sha256:f1af08da4ecea5036cb81c9131946be4404245d1b434b5b24fd3871a1d4030d9"}, + {file = "fiona-1.9.5-cp312-cp312-win_amd64.whl", hash = "sha256:c521e1135c78dec0d7774303e5a1b4c62e0efb0e602bb8f167550ef95e0a2691"}, + {file = "fiona-1.9.5-cp37-cp37m-macosx_10_15_x86_64.whl", hash = "sha256:fce4b1dd98810cabccdaa1828430c7402d283295c2ae31bea4f34188ea9e88d7"}, + {file = "fiona-1.9.5-cp37-cp37m-manylinux2014_x86_64.whl", hash = "sha256:3ea04ec2d8c57b5f81a31200fb352cb3242aa106fc3e328963f30ffbdf0ff7c8"}, + {file = "fiona-1.9.5-cp37-cp37m-win_amd64.whl", hash = "sha256:4877cc745d9e82b12b3eafce3719db75759c27bd8a695521202135b36b58c2e7"}, + {file = "fiona-1.9.5-cp38-cp38-macosx_10_15_x86_64.whl", hash = "sha256:ac2c250f509ec19fad7959d75b531984776517ef3c1222d1cc5b4f962825880b"}, + {file = "fiona-1.9.5-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:4df21906235928faad856c288cfea0298e9647f09c9a69a230535cbc8eadfa21"}, + {file = "fiona-1.9.5-cp38-cp38-manylinux2014_x86_64.whl", hash = "sha256:81d502369493687746cb8d3cd77e5ada4447fb71d513721c9a1826e4fb32b23a"}, + {file = "fiona-1.9.5-cp38-cp38-win_amd64.whl", hash = "sha256:ce3b29230ef70947ead4e701f3f82be81082b7f37fd4899009b1445cc8fc276a"}, + {file = "fiona-1.9.5-cp39-cp39-macosx_10_15_x86_64.whl", hash = "sha256:8b53ce8de773fcd5e2e102e833c8c58479edd8796a522f3d83ef9e08b62bfeea"}, + {file = "fiona-1.9.5-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:bd2355e859a1cd24a3e485c6dc5003129f27a2051629def70036535ffa7e16a4"}, + {file = "fiona-1.9.5-cp39-cp39-manylinux2014_x86_64.whl", hash = "sha256:9a2da52f865db1aff0eaf41cdd4c87a7c079b3996514e8e7a1ca38457309e825"}, + {file = "fiona-1.9.5-cp39-cp39-win_amd64.whl", hash = "sha256:cfef6db5b779d463298b1113b50daa6c5b55f26f834dc9e37752116fa17277c1"}, + {file = "fiona-1.9.5.tar.gz", hash = "sha256:99e2604332caa7692855c2ae6ed91e1fffdf9b59449aa8032dd18e070e59a2f7"}, +] + +[package.dependencies] +attrs = ">=19.2.0" +certifi = "*" +click = ">=8.0,<9.0" +click-plugins = ">=1.0" +cligj = ">=0.5" +setuptools = "*" +six = "*" + +[package.extras] +all = ["Fiona[calc,s3,test]"] +calc = ["shapely"] +s3 = ["boto3 (>=1.3.1)"] +test = ["Fiona[s3]", "pytest (>=7)", "pytest-cov", "pytz"] + +[[package]] +name = "geopandas" +version = "0.14.2" +description = "Geographic pandas extensions" +optional = false +python-versions = ">=3.9" +files = [ + {file = "geopandas-0.14.2-py3-none-any.whl", hash = "sha256:0efa61235a68862c1c6be89fc3707cdeba67667d5676bb19e24f3c57a8c2f723"}, + {file = "geopandas-0.14.2.tar.gz", hash = "sha256:6e71d57b8376f9fdc9f1c3aa3170e7e420e91778de854f51013ae66fd371ccdb"}, +] + +[package.dependencies] +fiona = ">=1.8.21" +packaging = "*" +pandas = ">=1.4.0" +pyproj = ">=3.3.0" +shapely = ">=1.8.0" + [[package]] name = "greenlet" version = "2.0.2" @@ -305,6 +424,7 @@ files = [ {file = "greenlet-2.0.2-cp27-cp27m-win32.whl", hash = "sha256:6c3acb79b0bfd4fe733dff8bc62695283b57949ebcca05ae5c129eb606ff2d74"}, {file = "greenlet-2.0.2-cp27-cp27m-win_amd64.whl", hash = "sha256:283737e0da3f08bd637b5ad058507e578dd462db259f7f6e4c5c365ba4ee9343"}, {file = "greenlet-2.0.2-cp27-cp27mu-manylinux2010_x86_64.whl", hash = "sha256:d27ec7509b9c18b6d73f2f5ede2622441de812e7b1a80bbd446cb0633bd3d5ae"}, + {file = "greenlet-2.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d967650d3f56af314b72df7089d96cda1083a7fc2da05b375d2bc48c82ab3f3c"}, {file = "greenlet-2.0.2-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:30bcf80dda7f15ac77ba5af2b961bdd9dbc77fd4ac6105cee85b0d0a5fcf74df"}, {file = "greenlet-2.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:26fbfce90728d82bc9e6c38ea4d038cba20b7faf8a0ca53a9c07b67318d46088"}, {file = "greenlet-2.0.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9190f09060ea4debddd24665d6804b995a9c122ef5917ab26e1566dcc712ceeb"}, @@ -313,6 +433,7 @@ files = [ {file = "greenlet-2.0.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:76ae285c8104046b3a7f06b42f29c7b73f77683df18c49ab5af7983994c2dd91"}, {file = "greenlet-2.0.2-cp310-cp310-win_amd64.whl", hash = "sha256:2d4686f195e32d36b4d7cf2d166857dbd0ee9f3d20ae349b6bf8afc8485b3645"}, {file = "greenlet-2.0.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:c4302695ad8027363e96311df24ee28978162cdcdd2006476c43970b384a244c"}, + {file = "greenlet-2.0.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:d4606a527e30548153be1a9f155f4e283d109ffba663a15856089fb55f933e47"}, {file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c48f54ef8e05f04d6eff74b8233f6063cb1ed960243eacc474ee73a2ea8573ca"}, {file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a1846f1b999e78e13837c93c778dcfc3365902cfb8d1bdb7dd73ead37059f0d0"}, {file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3a06ad5312349fec0ab944664b01d26f8d1f05009566339ac6f63f56589bc1a2"}, @@ -342,6 +463,7 @@ files = [ {file = "greenlet-2.0.2-cp37-cp37m-win32.whl", hash = "sha256:3f6ea9bd35eb450837a3d80e77b517ea5bc56b4647f5502cd28de13675ee12f7"}, {file = "greenlet-2.0.2-cp37-cp37m-win_amd64.whl", hash = "sha256:7492e2b7bd7c9b9916388d9df23fa49d9b88ac0640db0a5b4ecc2b653bf451e3"}, {file = "greenlet-2.0.2-cp38-cp38-macosx_10_15_x86_64.whl", hash = "sha256:b864ba53912b6c3ab6bcb2beb19f19edd01a6bfcbdfe1f37ddd1778abfe75a30"}, + {file = "greenlet-2.0.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:1087300cf9700bbf455b1b97e24db18f2f77b55302a68272c56209d5587c12d1"}, {file = "greenlet-2.0.2-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:ba2956617f1c42598a308a84c6cf021a90ff3862eddafd20c3333d50f0edb45b"}, {file = "greenlet-2.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fc3a569657468b6f3fb60587e48356fe512c1754ca05a564f11366ac9e306526"}, {file = "greenlet-2.0.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8eab883b3b2a38cc1e050819ef06a7e6344d4a990d24d45bc6f2cf959045a45b"}, @@ -350,6 +472,7 @@ files = [ {file = "greenlet-2.0.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b0ef99cdbe2b682b9ccbb964743a6aca37905fda5e0452e5ee239b1654d37f2a"}, {file = "greenlet-2.0.2-cp38-cp38-win32.whl", hash = "sha256:b80f600eddddce72320dbbc8e3784d16bd3fb7b517e82476d8da921f27d4b249"}, {file = "greenlet-2.0.2-cp38-cp38-win_amd64.whl", hash = "sha256:4d2e11331fc0c02b6e84b0d28ece3a36e0548ee1a1ce9ddde03752d9b79bba40"}, + {file = "greenlet-2.0.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:8512a0c38cfd4e66a858ddd1b17705587900dd760c6003998e9472b77b56d417"}, {file = "greenlet-2.0.2-cp39-cp39-macosx_11_0_x86_64.whl", hash = "sha256:88d9ab96491d38a5ab7c56dd7a3cc37d83336ecc564e4e8816dbed12e5aaefc8"}, {file = "greenlet-2.0.2-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:561091a7be172ab497a3527602d467e2b3fbe75f9e783d8b8ce403fa414f71a6"}, {file = "greenlet-2.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:971ce5e14dc5e73715755d0ca2975ac88cfdaefcaab078a284fea6cfabf866df"}, @@ -830,6 +953,45 @@ files = [ [package.dependencies] typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" +[[package]] +name = "pyproj" +version = "3.6.1" +description = "Python interface to PROJ (cartographic projections and coordinate transformations library)" +optional = false +python-versions = ">=3.9" +files = [ + {file = "pyproj-3.6.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:ab7aa4d9ff3c3acf60d4b285ccec134167a948df02347585fdd934ebad8811b4"}, + {file = "pyproj-3.6.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:4bc0472302919e59114aa140fd7213c2370d848a7249d09704f10f5b062031fe"}, + {file = "pyproj-3.6.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5279586013b8d6582e22b6f9e30c49796966770389a9d5b85e25a4223286cd3f"}, + {file = "pyproj-3.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:80fafd1f3eb421694857f254a9bdbacd1eb22fc6c24ca74b136679f376f97d35"}, + {file = "pyproj-3.6.1-cp310-cp310-win32.whl", hash = "sha256:c41e80ddee130450dcb8829af7118f1ab69eaf8169c4bf0ee8d52b72f098dc2f"}, + {file = "pyproj-3.6.1-cp310-cp310-win_amd64.whl", hash = "sha256:db3aedd458e7f7f21d8176f0a1d924f1ae06d725228302b872885a1c34f3119e"}, + {file = "pyproj-3.6.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:ebfbdbd0936e178091309f6cd4fcb4decd9eab12aa513cdd9add89efa3ec2882"}, + {file = "pyproj-3.6.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:447db19c7efad70ff161e5e46a54ab9cc2399acebb656b6ccf63e4bc4a04b97a"}, + {file = "pyproj-3.6.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e7e13c40183884ec7f94eb8e0f622f08f1d5716150b8d7a134de48c6110fee85"}, + {file = "pyproj-3.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65ad699e0c830e2b8565afe42bd58cc972b47d829b2e0e48ad9638386d994915"}, + {file = "pyproj-3.6.1-cp311-cp311-win32.whl", hash = "sha256:8b8acc31fb8702c54625f4d5a2a6543557bec3c28a0ef638778b7ab1d1772132"}, + {file = "pyproj-3.6.1-cp311-cp311-win_amd64.whl", hash = "sha256:38a3361941eb72b82bd9a18f60c78b0df8408416f9340521df442cebfc4306e2"}, + {file = "pyproj-3.6.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:1e9fbaf920f0f9b4ee62aab832be3ae3968f33f24e2e3f7fbb8c6728ef1d9746"}, + {file = "pyproj-3.6.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:6d227a865356f225591b6732430b1d1781e946893789a609bb34f59d09b8b0f8"}, + {file = "pyproj-3.6.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:83039e5ae04e5afc974f7d25ee0870a80a6bd6b7957c3aca5613ccbe0d3e72bf"}, + {file = "pyproj-3.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fffb059ba3bced6f6725961ba758649261d85ed6ce670d3e3b0a26e81cf1aa8d"}, + {file = "pyproj-3.6.1-cp312-cp312-win32.whl", hash = "sha256:2d6ff73cc6dbbce3766b6c0bce70ce070193105d8de17aa2470009463682a8eb"}, + {file = "pyproj-3.6.1-cp312-cp312-win_amd64.whl", hash = "sha256:7a27151ddad8e1439ba70c9b4b2b617b290c39395fa9ddb7411ebb0eb86d6fb0"}, + {file = "pyproj-3.6.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:4ba1f9b03d04d8cab24d6375609070580a26ce76eaed54631f03bab00a9c737b"}, + {file = "pyproj-3.6.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:18faa54a3ca475bfe6255156f2f2874e9a1c8917b0004eee9f664b86ccc513d3"}, + {file = "pyproj-3.6.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fd43bd9a9b9239805f406fd82ba6b106bf4838d9ef37c167d3ed70383943ade1"}, + {file = "pyproj-3.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:50100b2726a3ca946906cbaa789dd0749f213abf0cbb877e6de72ca7aa50e1ae"}, + {file = "pyproj-3.6.1-cp39-cp39-win32.whl", hash = "sha256:9274880263256f6292ff644ca92c46d96aa7e57a75c6df3f11d636ce845a1877"}, + {file = "pyproj-3.6.1-cp39-cp39-win_amd64.whl", hash = "sha256:36b64c2cb6ea1cc091f329c5bd34f9c01bb5da8c8e4492c709bda6a09f96808f"}, + {file = "pyproj-3.6.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:fd93c1a0c6c4aedc77c0fe275a9f2aba4d59b8acf88cebfc19fe3c430cfabf4f"}, + {file = "pyproj-3.6.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6420ea8e7d2a88cb148b124429fba8cd2e0fae700a2d96eab7083c0928a85110"}, + {file = "pyproj-3.6.1.tar.gz", hash = "sha256:44aa7c704c2b7d8fb3d483bbf75af6cb2350d30a63b144279a09b75fead501bf"}, +] + +[package.dependencies] +certifi = "*" + [[package]] name = "pytest" version = "7.4.0" @@ -963,6 +1125,79 @@ files = [ {file = "ruff-0.0.249.tar.gz", hash = "sha256:b590689f08ecef971c45555cbda6854cdf48f3828fc326802828e851b1a14b3d"}, ] +[[package]] +name = "setuptools" +version = "69.0.3" +description = "Easily download, build, install, upgrade, and uninstall Python packages" +optional = false +python-versions = ">=3.8" +files = [ + {file = "setuptools-69.0.3-py3-none-any.whl", hash = "sha256:385eb4edd9c9d5c17540511303e39a147ce2fc04bc55289c322b9e5904fe2c05"}, + {file = "setuptools-69.0.3.tar.gz", hash = "sha256:be1af57fc409f93647f2e8e4573a142ed38724b8cdd389706a867bb4efcf1e78"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.1)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] + +[[package]] +name = "shapely" +version = "2.0.2" +description = "Manipulation and analysis of geometric objects" +optional = false +python-versions = ">=3.7" +files = [ + {file = "shapely-2.0.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:6ca8cffbe84ddde8f52b297b53f8e0687bd31141abb2c373fd8a9f032df415d6"}, + {file = "shapely-2.0.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:baa14fc27771e180c06b499a0a7ba697c7988c7b2b6cba9a929a19a4d2762de3"}, + {file = "shapely-2.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:36480e32c434d168cdf2f5e9862c84aaf4d714a43a8465ae3ce8ff327f0affb7"}, + {file = "shapely-2.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4ef753200cbffd4f652efb2c528c5474e5a14341a473994d90ad0606522a46a2"}, + {file = "shapely-2.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a9a41ff4323fc9d6257759c26eb1cf3a61ebc7e611e024e6091f42977303fd3a"}, + {file = "shapely-2.0.2-cp310-cp310-win32.whl", hash = "sha256:72b5997272ae8c25f0fd5b3b967b3237e87fab7978b8d6cd5fa748770f0c5d68"}, + {file = "shapely-2.0.2-cp310-cp310-win_amd64.whl", hash = "sha256:34eac2337cbd67650248761b140d2535855d21b969d76d76123317882d3a0c1a"}, + {file = "shapely-2.0.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:5b0c052709c8a257c93b0d4943b0b7a3035f87e2d6a8ac9407b6a992d206422f"}, + {file = "shapely-2.0.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:2d217e56ae067e87b4e1731d0dc62eebe887ced729ba5c2d4590e9e3e9fdbd88"}, + {file = "shapely-2.0.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:94ac128ae2ab4edd0bffcd4e566411ea7bdc738aeaf92c32a8a836abad725f9f"}, + {file = "shapely-2.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fa3ee28f5e63a130ec5af4dc3c4cb9c21c5788bb13c15e89190d163b14f9fb89"}, + {file = "shapely-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:737dba15011e5a9b54a8302f1748b62daa207c9bc06f820cd0ad32a041f1c6f2"}, + {file = "shapely-2.0.2-cp311-cp311-win32.whl", hash = "sha256:45ac6906cff0765455a7b49c1670af6e230c419507c13e2f75db638c8fc6f3bd"}, + {file = "shapely-2.0.2-cp311-cp311-win_amd64.whl", hash = "sha256:dc9342fc82e374130db86a955c3c4525bfbf315a248af8277a913f30911bed9e"}, + {file = "shapely-2.0.2-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:06f193091a7c6112fc08dfd195a1e3846a64306f890b151fa8c63b3e3624202c"}, + {file = "shapely-2.0.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:eebe544df5c018134f3c23b6515877f7e4cd72851f88a8d0c18464f414d141a2"}, + {file = "shapely-2.0.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:7e92e7c255f89f5cdf777690313311f422aa8ada9a3205b187113274e0135cd8"}, + {file = "shapely-2.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:be46d5509b9251dd9087768eaf35a71360de6afac82ce87c636990a0871aa18b"}, + {file = "shapely-2.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a5533a925d8e211d07636ffc2fdd9a7f9f13d54686d00577eeb11d16f00be9c4"}, + {file = "shapely-2.0.2-cp312-cp312-win32.whl", hash = "sha256:084b023dae8ad3d5b98acee9d3bf098fdf688eb0bb9b1401e8b075f6a627b611"}, + {file = "shapely-2.0.2-cp312-cp312-win_amd64.whl", hash = "sha256:ea84d1cdbcf31e619d672b53c4532f06253894185ee7acb8ceb78f5f33cbe033"}, + {file = "shapely-2.0.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:ed1e99702125e7baccf401830a3b94d810d5c70b329b765fe93451fe14cf565b"}, + {file = "shapely-2.0.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e7d897e6bdc6bc64f7f65155dbbb30e49acaabbd0d9266b9b4041f87d6e52b3a"}, + {file = "shapely-2.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0521d76d1e8af01e712db71da9096b484f081e539d4f4a8c97342e7971d5e1b4"}, + {file = "shapely-2.0.2-cp37-cp37m-win32.whl", hash = "sha256:5324be299d4c533ecfcfd43424dfd12f9428fd6f12cda38a4316da001d6ef0ea"}, + {file = "shapely-2.0.2-cp37-cp37m-win_amd64.whl", hash = "sha256:78128357a0cee573257a0c2c388d4b7bf13cb7dbe5b3fe5d26d45ebbe2a39e25"}, + {file = "shapely-2.0.2-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:87dc2be34ac3a3a4a319b963c507ac06682978a5e6c93d71917618b14f13066e"}, + {file = "shapely-2.0.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:42997ac806e4583dad51c80a32d38570fd9a3d4778f5e2c98f9090aa7db0fe91"}, + {file = "shapely-2.0.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:ccfd5fa10a37e67dbafc601c1ddbcbbfef70d34c3f6b0efc866ddbdb55893a6c"}, + {file = "shapely-2.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e7c95d3379ae3abb74058938a9fcbc478c6b2e28d20dace38f8b5c587dde90aa"}, + {file = "shapely-2.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6a21353d28209fb0d8cc083e08ca53c52666e0d8a1f9bbe23b6063967d89ed24"}, + {file = "shapely-2.0.2-cp38-cp38-win32.whl", hash = "sha256:03e63a99dfe6bd3beb8d5f41ec2086585bb969991d603f9aeac335ad396a06d4"}, + {file = "shapely-2.0.2-cp38-cp38-win_amd64.whl", hash = "sha256:c6fd29fbd9cd76350bd5cc14c49de394a31770aed02d74203e23b928f3d2f1aa"}, + {file = "shapely-2.0.2-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:1f217d28ecb48e593beae20a0082a95bd9898d82d14b8fcb497edf6bff9a44d7"}, + {file = "shapely-2.0.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:394e5085b49334fd5b94fa89c086edfb39c3ecab7f669e8b2a4298b9d523b3a5"}, + {file = "shapely-2.0.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:fd3ad17b64466a033848c26cb5b509625c87d07dcf39a1541461cacdb8f7e91c"}, + {file = "shapely-2.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d41a116fcad58048d7143ddb01285e1a8780df6dc1f56c3b1e1b7f12ed296651"}, + {file = "shapely-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dea9a0651333cf96ef5bb2035044e3ad6a54f87d90e50fe4c2636debf1b77abc"}, + {file = "shapely-2.0.2-cp39-cp39-win32.whl", hash = "sha256:b8eb0a92f7b8c74f9d8fdd1b40d395113f59bd8132ca1348ebcc1f5aece94b96"}, + {file = "shapely-2.0.2-cp39-cp39-win_amd64.whl", hash = "sha256:794affd80ca0f2c536fc948a3afa90bd8fb61ebe37fe873483ae818e7f21def4"}, + {file = "shapely-2.0.2.tar.gz", hash = "sha256:1713cc04c171baffc5b259ba8531c58acc2a301707b7f021d88a15ed090649e7"}, +] + +[package.dependencies] +numpy = ">=1.14" + +[package.extras] +docs = ["matplotlib", "numpydoc (==1.1.*)", "sphinx", "sphinx-book-theme", "sphinx-remove-toctrees"] +test = ["pytest", "pytest-cov"] + [[package]] name = "six" version = "1.16.0" @@ -1212,4 +1447,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "f14f177e9051d7ba2cb8b2a1a28598fa5ff4b51e4d1e193cbfbac5d3c09d4458" +content-hash = "4f20b0cf1ec7ca3601e5ee0b30605b2b4824534813ed610bf000563fadc635a6" diff --git a/pvsite_datamodel/write/data/dno.py b/pvsite_datamodel/write/data/dno.py new file mode 100644 index 0000000..2d3fc47 --- /dev/null +++ b/pvsite_datamodel/write/data/dno.py @@ -0,0 +1,62 @@ +""" The script adds the relevant GSP to the sites. + +Might need to install nowcasting_dataset + +and we want to added the gsp as {gsp_id}|{gsp_nam} into the database + +1. Load in dno data from NG +2. Load all sites +3. For each site add dno + +""" +import logging +import os + +import geopandas as gpd +from shapely.geometry import Point + +from pvsite_datamodel.write.data.utils import lat_lon_to_osgb + +logger = logging.getLogger(__name__) +dir_path = os.path.dirname(os.path.realpath(__file__)) +dno_local_file = f"{dir_path}/dno" + + +def get_dno(latitude, longitude) -> dict: + """ + Convert a latitude and longitude and returns the dno. + + :param latitude: + :param longitude: + + :return: dno is this format {"dno_id": dno_id, "name": dno_name, "long_name": dno_long_name}= + """ + + # load file + dno = gpd.read_file(dno_local_file) + + # change lat lon to osgb + x, y = lat_lon_to_osgb(lat=latitude, lon=longitude) + point = Point(x, y) + + # select dno + mask = dno.contains(point) + dno = dno[mask] + + # format dno + if len(dno) == 1: + dno = dno.iloc[0] + + dno_id = dno["ID"] + name = dno["Name"] + long_name = dno["LongName"] + + dno_dict = {"dno_id": str(dno_id), "name": name, "long_name": long_name} + logger.debug(dno_dict) + else: + dno_dict = {"dno_id": "999", "name": "unknown", "long_name": "unknown"} + + return dno_dict + + +# diff --git a/pvsite_datamodel/write/data/dno/dno.cpg b/pvsite_datamodel/write/data/dno/dno.cpg new file mode 100644 index 0000000..cd89cb9 --- /dev/null +++ b/pvsite_datamodel/write/data/dno/dno.cpg @@ -0,0 +1 @@ +ISO-8859-1 \ No newline at end of file diff --git a/pvsite_datamodel/write/data/dno/dno.dbf b/pvsite_datamodel/write/data/dno/dno.dbf new file mode 100644 index 0000000..c3d2d9f Binary files /dev/null and b/pvsite_datamodel/write/data/dno/dno.dbf differ diff --git a/pvsite_datamodel/write/data/dno/dno.prj b/pvsite_datamodel/write/data/dno/dno.prj new file mode 100644 index 0000000..fec0ee2 --- /dev/null +++ b/pvsite_datamodel/write/data/dno/dno.prj @@ -0,0 +1 @@ +PROJCS["British_National_Grid",GEOGCS["GCS_OSGB_1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000.0],PARAMETER["False_Northing",-100000.0],PARAMETER["Central_Meridian",-2.0],PARAMETER["Scale_Factor",0.9996012717],PARAMETER["Latitude_Of_Origin",49.0],UNIT["Meter",1.0]] \ No newline at end of file diff --git a/pvsite_datamodel/write/data/dno/dno.shp b/pvsite_datamodel/write/data/dno/dno.shp new file mode 100644 index 0000000..0270352 Binary files /dev/null and b/pvsite_datamodel/write/data/dno/dno.shp differ diff --git a/pvsite_datamodel/write/data/dno/dno.shx b/pvsite_datamodel/write/data/dno/dno.shx new file mode 100644 index 0000000..48af78d Binary files /dev/null and b/pvsite_datamodel/write/data/dno/dno.shx differ diff --git a/pvsite_datamodel/write/data/gsp.py b/pvsite_datamodel/write/data/gsp.py new file mode 100644 index 0000000..71cc692 --- /dev/null +++ b/pvsite_datamodel/write/data/gsp.py @@ -0,0 +1,51 @@ +""" GSP functions for UK regions. """ +import logging +import os + +import geopandas as gpd +import pandas as pd +from shapely.geometry import Point + +from pvsite_datamodel.write.data.utils import lat_lon_to_osgb + +logger = logging.getLogger(__name__) + +dir_path = os.path.dirname(os.path.realpath(__file__)) +gsp_local_file = f"{dir_path}/gsp" +gsp_names = pd.read_csv(f"{dir_path}/gsp_new_ids_and_names-edited.csv") + + +def get_gsp(latitude, longitude) -> dict: + """ + Get a DNO from latitude and longitude. + + :param latitude: + :param longitude: + + :return: dno is this format {"dno_id": dno_id, "name": dno_name, "long_name": dno_long_name}= + """ + + # load file + gsp = gpd.read_file(gsp_local_file) + + # change lat lon to osgb + x, y = lat_lon_to_osgb(lat=latitude, lon=longitude) + point = Point(x, y) + + # select gsp + mask = gsp.contains(point) + gsp = gsp[mask] + + # format gsp + if len(gsp) == 1: + gsp = gsp.iloc[0] + gsp_details = gsp_names[gsp_names["gsp_name"] == gsp.GSPs] + gsp_id = gsp_details.index[0] + gsp_details = gsp_details.iloc[0] + name = gsp_details["region_name"] + + gsp_dict = {"gsp_id": str(gsp_id), "name": name} + else: + gsp_dict = {"gsp_id": "999", "name": "unknown"} + + return gsp_dict diff --git a/pvsite_datamodel/write/data/gsp/gsp.cpg b/pvsite_datamodel/write/data/gsp/gsp.cpg new file mode 100644 index 0000000..cd89cb9 --- /dev/null +++ b/pvsite_datamodel/write/data/gsp/gsp.cpg @@ -0,0 +1 @@ +ISO-8859-1 \ No newline at end of file diff --git a/pvsite_datamodel/write/data/gsp/gsp.dbf b/pvsite_datamodel/write/data/gsp/gsp.dbf new file mode 100644 index 0000000..113aba1 Binary files /dev/null and b/pvsite_datamodel/write/data/gsp/gsp.dbf differ diff --git a/pvsite_datamodel/write/data/gsp/gsp.prj b/pvsite_datamodel/write/data/gsp/gsp.prj new file mode 100644 index 0000000..fec0ee2 --- /dev/null +++ b/pvsite_datamodel/write/data/gsp/gsp.prj @@ -0,0 +1 @@ +PROJCS["British_National_Grid",GEOGCS["GCS_OSGB_1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000.0],PARAMETER["False_Northing",-100000.0],PARAMETER["Central_Meridian",-2.0],PARAMETER["Scale_Factor",0.9996012717],PARAMETER["Latitude_Of_Origin",49.0],UNIT["Meter",1.0]] \ No newline at end of file diff --git a/pvsite_datamodel/write/data/gsp/gsp.shp b/pvsite_datamodel/write/data/gsp/gsp.shp new file mode 100644 index 0000000..5fee419 Binary files /dev/null and b/pvsite_datamodel/write/data/gsp/gsp.shp differ diff --git a/pvsite_datamodel/write/data/gsp/gsp.shx b/pvsite_datamodel/write/data/gsp/gsp.shx new file mode 100644 index 0000000..cf0979a Binary files /dev/null and b/pvsite_datamodel/write/data/gsp/gsp.shx differ diff --git a/pvsite_datamodel/write/data/gsp_new_ids_and_names-edited.csv b/pvsite_datamodel/write/data/gsp_new_ids_and_names-edited.csv new file mode 100644 index 0000000..c2de170 --- /dev/null +++ b/pvsite_datamodel/write/data/gsp_new_ids_and_names-edited.csv @@ -0,0 +1,319 @@ +,gsp_id_x,gsp_name,region_name +0,0,NATIONAL, National +1,1,ABHA1,Abham +2,2,ABNE_P,Abernethy +3,3,ABTH_1,Aberthaw +4,4,ACTL_2|CBNK_H|GREE_H|PERI_H,Willesden (Zone 1) +5,5,ACTL_C|WISD_1|WISD_6,Willesden (Zone 2) +6,6,ALNE_P,Alness +7,7,ALST_3|USKM_1,Uskmouth +8,8,ALVE1,Alverdiscott +9,9,AMEM_1,Amersham Main +10,10,ARBR_P,Arbroath +11,11,ARDK_P|CLAC_P,Clachan +12,12,ARMO_P,Ardmore +13,13,AXMI1,Axminster +14,14,AYRR,Ayr +15,15,BAGA,Bathgate +16,16,BAIN,Bainsford +17,17,BARKC1|BARKW3,Barking +18,18,BEAU_P|ORRI_P,Beauly +19,19,BEDDT1,Beddington (Zone 1) +20,20,BEDD_1,Beddington (Zone 2) +21,21,BERB_P|CAIF_P|DALL_P|GLEF_P|KEIT_P,Keith +22,22,BERW,Berwick +23,23,BESW_1,Berkswell +24,24,BICF_1,Bicker Fen +25,25,BIRK_1,Birkenhead +26,26,BISW_1,Bishops Wood +27,27,BLYTB1,Blyth (Zone 1) +28,28,BLYTH132,Blyth (Zone 2) +30,29,BOAG_P,Boat of Garten +31,30,BOLN_1,Bolney +32,31,BONN,Bonnybridge +33,32,BOTW_1,Botley Wood +34,33,BRAC_P,Braco West +35,34,BRAI_1,Braintree +36,35,BRAP,Braehead Park +37,36,BRAW_1,Bradford West +38,37,BRED_1,Bredbury +39,38,BRFO_1|CLT03,Bramford +40,39,BRID_P,Bridge of Dun +41,40,BRIM_1,Brimsdown +42,41,BRLE_1|FLEE_1,Bramley +43,42,BROA_P,Broadford +44,43,BROR_P,Brora +45,44,BROX,Broxburn +46,45,BRWA1,Bridgewater +47,46,BUMU_P,Burghmuir +48,47,BURM_1,Burwell Main +49,48,BUSH_1,Bushbury +50,49,BUST_1,Bustleholme +51,50,CAAD_P,Carradale +52,51,CAFA|EAST|GLLE|KEOO|TONG,Tongland +53,52,CAMB_01,Camblesforth +54,53,CANTN1|RICH_J|RICH1,Canterbury +55,54,CAPEA1,Capenhurst +57,55,CARE_1,Cardiff East +58,56,CARR_1,Carrington +60,57,CASS_P,Cassley +61,58,CATY,Carntyne +62,59,CEAN_P,Ceannacroc +63,60,CELL_1,Cellarhead +64,61,CHAP,Chapelcross +65,62,CHAR_P,Charleston +66,63,CHAS,Charlotte Street +67,64,CHIC_1,Chickerell +68,65,CHSI_1,Chessington +70,66,CHTE_1,Chesterfield +71,67,CITR_1,City Road +72,68,CLAY_P,Clayhills +73,69,CLYM,Clyde’s Mill +74,70,COAT,Coatbridge +76,71,COCK,Cockenzie +77,72,CONQA1|SASA,Connahs Quay +78,73,COUA_P,Coupar Angus +79,74,COVE_1,Coventry +80,75,COWL_1|ECLA_H,Cowley +81,76,COYL,Coylton +82,77,CRAI_P,Craigiebuckler +83,78,CREB_1,Creyke Beck +84,79,CROO,Crookston +86,80,CUMB,Cumbernauld +87,81,CUPA,Cupar +88,82,CURR,Currie +89,83,DALM3,Dalmarnock +90,84,DEVM,Devol Moor +91,85,DEVO,Devonside +92,86,DEWP,Dewar Place +93,87,DOUN_P,Dounreay +94,88,DRAK_1,Drakelow +95,89,DRAX_1,Drax +96,90,DRCR,Drumcross +97,91,DRUM,Drumchapel +98,92,DUBE_P,Dunbeath +99,93,DUDH_P,Dudhope +100,94,DUGR_P,Dunvegan +101,95,DUMF,Dumfries +104,96,DUNB,Dunbar +105,97,DUNF,Dunfermline +106,98,DUNO_P,Dunoon +107,99,DYCE_P,Dyce +108,100,EALI_6,Ealing +109,101,EASO_1,Eaton Socon +110,102,ECCL,Eccles +111,103,ECLA_1,East Claydon +112,104,EERH,Easterhouse +113,105,EKIL,East Kilbride +114,106,EKIS,East Kilbride South +115,107,ELDE,Elderslie +116,108,ELGI_P,Elgin +117,109,ELLA_1,Elland +118,110,ELST_1,Elstree +121,111,ENDE_1,Enderby +122,112,ERSK,Erskine +123,113,EXET1,Exeter +124,114,FASN_P,Fasnakyle +125,115,FAUG_P,Fort Augustus +126,116,FAWL_1,Fawley +127,117,FECK_6,Feckenham +128,118,FERRA2,Ferrybridge (Zone 1) +129,119,FERRB_M|FERRB1,Ferrybridge (Zone 2) +130,120,FETT_P|KINT_P,Kintore +131,121,FIDD_P,Fiddes +132,122,FIDF_1,Fiddlers Ferry +133,123,FINN,Finnieston +134,124,FOUR_1,Fourstones +135,125,FRAS_P,Fraserburgh +136,126,FROD_1,Frodsham +137,127,FWIL_P,Fort William +138,128,GALA,Galashiels +139,129,GIFF,Giffnock +140,130,GLLU,Glenluce +141,131,GLNI,Glenniston +142,132,GLRO,Glenrothes +143,133,GORG,Gorgie +144,134,GOVA,Govan +145,135,GREN_1,Grendon +146,136,GRIW_1,Grimsby West +147,137,GRMO,Grangemouth +149,138,GRUB_P,Grudie Bridge +150,139,G_EXTRA_12,G_EXTRA_12 +151,140,HACK_1|HACK_6,Hackney +152,141,HAGR,Haggs Road +153,142,HAMHC1,Hams Hall +154,143,HARK_1|HUTT_1|RRIG,Hutton +155,144,HARM_6,Hart Moor +156,145,HAWI,Hawick +157,146,HAWP_6,Hawthorn Pit +158,147,HELE,Helensburgh +159,148,HEYS_1|HEYS1|ORMO,Heysham +160,149,HUER,Hunterston Farm +161,150,HURS_1,Hurst +162,151,IMPK_1,Imperial Park +163,152,INDQ1,Indian Queens +164,153,INKE,Inverkeithing +165,154,INNE_P,Inverness +166,155,IROA1,Iron Acton +167,156,IRONB1,Ironbridge +168,157,ISLI_1|WHAM_1,West Ham +169,158,IVER_1|IVER_6,Iver +170,159,JOHN,Johnstone +171,160,JORD_3,Jordanthorpe +172,161,KAIM,Kaimes +173,162,KEAD_1,Keadby +174,163,KEAR_1|KEAR_3,Kearsley +175,164,KEMS_1,Kemsley +177,165,KIBY_1,Kirkby (Zone 1) +178,166,KIBY_G|WASF_1,Kirkby (Zone 2) +179,167,KIER,Killermont +180,168,KIIN_P,Killin +181,169,KILB,Kilbowie +183,170,KILS,Kilmarnock South +184,171,KILT,Kilmarnock Town +185,172,KILW,Kilwinning +186,173,KINL_P,Kinlochleven +187,174,KINO_1,Kingsnorth +188,175,KIRKB1,Kirkstall +189,176,KITW_1,Kitwell +190,177,KNAR,Knaresborough +191,178,LACK_6,Lackenby +192,179,LAIR_P,Lairg +193,180,LALE1SG003,Laleham +194,181,LAND1,Landulph +195,182,LEGA_1,Legacy +196,183,LEVE,Leven +197,184,LING,Livingston East +198,185,LINM,Linnmill +199,186,LISD_1,Lister Drive +200,187,LITT_C,Littlebrook (Zone 1) +201,188,LITT_J,Littlebrook (Zone 2) +202,189,LODR_6,Lodge Road +203,190,LOUD_H,Loudwater +204,191,LOVE_1,Lovedean +205,192,LUNA_P,Lunanhead +206,193,LYND_P,Lyndhurst +207,194,MACC_3,Macclesfield +208,195,MACD_P,Macduff +209,196,MAGA_6,Margam +210,197,MANN_1,Mannington +211,198,MAYB,Maybole +212,199,MELK_1,Melksham +213,200,MILC_P,Milton of Craigie +214,201,MILH_1,Mill Hill +215,202,MITY_1,Minety +216,203,MYBS_P,Mybster +217,204,NAIR_P,Nairn +218,205,NEAR,Newarthill +219,206,NECE_1,Nechells +221,207,NEEP_3,Neepsend +222,208,NETS,Newton Stewart +223,209,NEWX_6,New Cross +225,210,NFLE,Northfleet East +226,211,NHYD_6,North Hyde +227,212,NINF_1,Ninfield +228,213,NORL_3,Norton Lees +229,214,NORM_1|SALL1,Norwich Main +230,215,NORT_1,Norton +231,216,NURS_1,Nursling +232,217,OCKH_1,Ocker Hill +233,218,OFFE_3,Offerton +234,219,OLDB_1,Oldbury +235,220,OSBA_1,Osbaldwick +236,221,PADIB1,Padiham +237,222,PAIS,Paisley +238,223,PART,Partick +239,224,PEHG_P,Peterhead Grange +240,225,PEHS_P|STRI_P,Peterhead Shell +241,226,PELH_1,Pelham +242,227,PEMB_1,Pembroke +243,228,PENE_1,Penwortham +244,229,PENN_1,Penn +245,230,PENT_1,Pentir +246,231,PENW_1|STAH_1|WABO,Penwortham +247,232,PERS_P,Persley +248,233,PITS_3,Pitsmoor +250,234,POOB,Portobello +251,235,POPP_3,Poppleton +252,236,PORA_P,Port Ann +253,237,PORD,Port Dundas +254,238,PYLE_1,Pyle +255,239,QUOI_P,Quoich +256,240,RAIN_1,Rainhill +257,241,RANN_P,Rannoch +258,242,RASS_1,Rassau +259,243,RATS_1,Ratcliffe +260,244,RAVE|WISH,Ravenscraig +261,245,RAYL_1,Rayleigh +262,246,REBR_3,Redbridge +263,247,REDH,Redhouse +264,248,REDM_P,Redmoss +265,249,ROCH_1,Rochdale +266,250,RUGEB1,Rugeley +267,251,RYEH_1,Rye House +268,252,SACO,Saltcoats +270,253,SALH_1,Saltholme +271,254,SALT_1,Saltend North +272,255,SANX,St Andrews Cross +273,256,SBAR,Stoke Bardolph +274,257,SEAB1,Seabank +275,258,SELL_1,Sellindge +277,259,SFEG_P,St Fergus Gas Terminal +278,260,SFIL_P,St Fillans +279,261,SHEC_3,Sheffield City +280,262,SHIN_P,Shin +281,263,SHRU,Shrubhill +282,264,SHRW_1,Shrewsbury +283,265,SIGH,Sighthill +284,266,SJOW_1,St Johns Wood +285,267,SKLGB1,Skelton Grange +286,268,SLOY_P,Sloy +287,269,SMAN_1,South Manchester +288,270,SPAV,Spango Valley +289,271,SPEN_1,Spennymoor +290,272,SSHI_3,South Shields +291,273,STAL_1,Stalybridge +292,274,STAY_1,Staythorpe +293,275,STEN_1,Stella North +294,276,STES_1,Stella South +295,277,STHA,Strathaven +296,278,STIR,Stirling +297,279,STLE,Strathleven +298,280,SUND_1,Sundon +299,281,SWAN_1,Swansea North +300,282,TARL_P,Tarland +301,283,TAUN1,Taunton +302,284,TAYN_P,Taynuilt +303,285,TELR,Telford Road +304,286,TEMP_3,Templeborough +305,287,THOM_6,Thorpe Marsh +306,288,THSO_P,Thurso +307,289,THUR_6,Thurcroft +308,290,TILBB_1,Tilbury +310,291,TOTT_1,Tottenham +311,292,TRAW_1,Trawsfynydd +312,293,TUMB_P,Tummel Bridge +313,294,TYNE_1|TYNE_2,Tynemouth +314,295,UPPB_1|UPPB_3,Upper Boat +315,296,WALH_1,Walham +316,297,WALP_1,Walpole (Zone 1) +317,298,WALP_B,Walpole (Zone 2) +318,299,WARL_1,Warley +319,300,WATFS_1,Watford South +320,301,WBOL_6,West Boldon +321,302,WBUR_1,West Burton +322,303,WFIE,Westfield +323,304,WGEO,West George Street +324,305,WHGA_1,Whitegate +325,306,WHHO,Whitehouse +326,307,WIBA_3,Wincobank +327,308,WIEN_1,Willenhall +328,309,WILL_1,Willington +329,310,WIMBN1|WIMBS1,Wimbledon +330,311,WIOW_P,Willowdale +331,312,WMEL_1,West Melton +332,313,WOHI_P,Woodhill +333,314,WTHU31,West Thurrock +334,315,WWEY_1,West Weybridge +335,316,WYLF_1,Wylfa +336,317,WYMOM_1,Wymondley diff --git a/pvsite_datamodel/write/data/utils.py b/pvsite_datamodel/write/data/utils.py new file mode 100644 index 0000000..f47c594 --- /dev/null +++ b/pvsite_datamodel/write/data/utils.py @@ -0,0 +1,60 @@ +""" Utils for GSP and DNO. """ +import pyproj + +# OSGB is also called "OSGB 1936 / British National Grid -- United +# Kingdom Ordnance Survey". OSGB is used in many UK electricity +# system maps, and is used by the UK Met Office UKV model. OSGB is a +# Transverse Mercator projection, using 'easting' and 'northing' +# coordinates which are in meters. See https://epsg.io/27700 + +# WGS84 is short for "World Geodetic System 1984", used in GPS. Uses +# latitude and longitude. + +OSGB = 27700 +WGS84 = 4326 +WGS84_CRS = f"EPSG:{WGS84}" + + +def lat_lon_to_osgb(lat: float, lon: float) -> [float, float]: + """ + Change lat, lon to a OSGB coordinates. + + lat: latitude + lon: longitude + + Return: 2-tuple of x (east-west), y (north-south). + + """ + return transformers.lat_lon_to_osgb.transform(lat, lon) + + +class Transformers: + """ + Class to store transformation from one Grid to another. + + Its good to make this only once, but need the + option of updating them, due to out of data grids. + """ + + def __init__(self): + """Init.""" + self._osgb_to_lat_lon = None + self._lat_lon_to_osgb = None + self._osgb_to_geostationary = None + self.make_transformers() + + def make_transformers(self): + """ + Make transformers. + + Nice to only make these once, as it makes calling the functions below quicker + """ + self._lat_lon_to_osgb = pyproj.Transformer.from_crs(crs_from=WGS84, crs_to=OSGB) + + @property + def lat_lon_to_osgb(self): + """lat-lon to OSGB property.""" + return self._lat_lon_to_osgb + + +transformers = Transformers() diff --git a/pvsite_datamodel/write/user_and_site.py b/pvsite_datamodel/write/user_and_site.py index b172007..b8a9cbf 100644 --- a/pvsite_datamodel/write/user_and_site.py +++ b/pvsite_datamodel/write/user_and_site.py @@ -1,14 +1,19 @@ """ Tools for making fake users and sites in the database.""" +import json from datetime import datetime, timezone +from typing import Optional import sqlalchemy as sa from sqlalchemy.orm.session import Session +from sqlalchemy.sql.functions import func from pvsite_datamodel.read import get_user_by_email from pvsite_datamodel.sqlmodels import ForecastSQL, ForecastValueSQL, SiteGroupSQL, SiteSQL, UserSQL +from pvsite_datamodel.write.data.dno import get_dno +from pvsite_datamodel.write.data.gsp import get_gsp -def make_site(db_session, ml_id=1): +def make_fake_site(db_session, ml_id=1): """Make a site. This is mainly used for testing purposes. @@ -30,7 +35,7 @@ def make_site(db_session, ml_id=1): return site -def make_site_group(db_session, site_group_name="test_site_group"): +def create_site_group(db_session, site_group_name="test_site_group"): """Make a site group. This is mainly used for testing purposes. @@ -43,22 +48,94 @@ def make_site_group(db_session, site_group_name="test_site_group"): return site_group -def make_user(db_session, email, site_group): - """Make a user. +# make site +def create_site( + session: Session, + client_site_id: int, + client_site_name: str, + latitude: float, + longitude: float, + capacity_kw: float, + dno: Optional[str] = None, + gsp: Optional[str] = None, + region: Optional[str] = None, + orientation: Optional[float] = None, + tilt: Optional[float] = None, + inverter_capacity_kw: Optional[float] = None, + module_capacity_kw: Optional[float] = None, +) -> [SiteSQL, str]: + """ + Create a site and adds it to the database. + + :param session: database session + :param client_site_id: id the client uses for the site + :param client_site_name: name the client uses for the site + :param latitude: latitude of site as an integer + :param longitude: longitude of site as an integer + :param capacity_kw: capacity of site in kw + :param dno: dno of site + :param gsp: gsp of site + :param region: region of site, deafut is uk + :param orientation: orientation of site, default is 180 + :param tilt: tilt of site, default is 35 + :param inverter_capacity_kw: inverter capacity of site in kw + :param module_capacity_kw: module capacity of site in kw - This is mainly used for testing purposes. """ - # create a user - user = UserSQL(email=email, site_group_uuid=site_group.site_group_uuid) - db_session.add(user) - db_session.commit() + max_ml_id = session.query(func.max(SiteSQL.ml_id)).scalar() - return user + if max_ml_id is None: + max_ml_id = 0 + + if region in [None, ""]: + region = "uk" + + if orientation in [None, ""]: + orientation = 180 + if tilt in [None, ""]: + tilt = 35 -# TODO move create_new site_function here. -# For the moment, data folder in ocf-dashboard has code this function depends on and this -# should probably be done in an new issue + if inverter_capacity_kw in [None, ""]: + inverter_capacity_kw = capacity_kw + + if module_capacity_kw in [None, ""]: + module_capacity_kw = capacity_kw + + if gsp is None: + gsp = get_gsp(latitude=latitude, longitude=longitude) + gsp = json.dumps(gsp) + + if dno is None: + dno = get_dno(latitude=latitude, longitude=longitude) + dno = json.dumps(dno) + + site = SiteSQL( + ml_id=max_ml_id + 1, + client_site_id=client_site_id, + client_site_name=client_site_name, + latitude=latitude, + longitude=longitude, + capacity_kw=capacity_kw, + dno=dno, + gsp=gsp, + region=region, + orientation=orientation, + tilt=tilt, + inverter_capacity_kw=inverter_capacity_kw, + module_capacity_kw=module_capacity_kw, + ) + + session.add(site) + + session.commit() + + message = ( + f"Site with client site id {site.client_site_id} " + f"and site uuid {site.site_uuid} created successfully" + ) + + return site, message def create_user( @@ -70,7 +147,7 @@ def create_user( :param session: database session :param email: email of user being created - :param site_group: name of the site group this user will be part of + :param site_group_name: name of the site group this user will be part of """ site_group = ( @@ -116,6 +193,7 @@ def change_user_site_group(session, email: str, site_group_name: str): :param session: the database session :param email: the email of the user + :param site_group_name: the name of the site group """ update_user_site_group(session=session, email=email, site_group_name=site_group_name) user = get_user_by_email(session=session, email=email) @@ -141,6 +219,8 @@ def update_user_site_group(session: Session, email: str, site_group_name: str) - session.commit() + return user + # delete functions for site, user, and site group def delete_site(session: Session, site_uuid: str) -> SiteGroupSQL: @@ -177,7 +257,7 @@ def delete_site(session: Session, site_uuid: str) -> SiteGroupSQL: # delete user -def delete_user(session: Session, email: str) -> UserSQL: +def delete_user(session: Session, email: str) -> str: """Delete a user. :param session: database session @@ -198,7 +278,7 @@ def delete_user(session: Session, email: str) -> UserSQL: # delete site group -def delete_site_group(session: Session, site_group_name: str) -> SiteGroupSQL: +def delete_site_group(session: Session, site_group_name: str) -> str: """Delete a site group. :param session: database session diff --git a/pyproject.toml b/pyproject.toml index c128496..43187db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ sqlalchemy = "1.4.46" psycopg2-binary = "^2.9.5" pandas = "^1.5.3" pydantic = "^2.3.0" +geopandas = "^0.14.2" [tool.poetry.group.dev.dependencies] diff --git a/scripts/download_dno_gsp.py b/scripts/download_dno_gsp.py new file mode 100644 index 0000000..eddba7f --- /dev/null +++ b/scripts/download_dno_gsp.py @@ -0,0 +1,49 @@ +""" Script us used to download DNO and GSP data from NG. """ +import logging +import os +import ssl + +import geopandas as gpd +import pandas as pd + +from pvsite_datamodel.write.data import utils + +logger = logging.getLogger(__name__) +dir_path = os.path.dirname(utils.__file__) +dno_local_file = f"{dir_path}/dno" + + +dir_path = os.path.dirname(utils.__file__) +gsp_local_file = f"{dir_path}/gsp" +gsp_names = pd.read_csv(f"{dir_path}/gsp_new_ids_and_names-edited.csv") + + +def download_dno(): + """Download DNO data from NG.""" + + logger.debug("Getting dno file") + ssl._create_default_https_context = ssl._create_unverified_context + url = "https://data.nationalgrideso.com/backend/dataset/0e377f16-95e9-4c15-a1fc-49e06a39cfa0/resource/e96db306-aaa8-45be-aecd-65b34d38923a/download/dno_license_areas_20200506.geojson" # noqa + dno_shapes = gpd.read_file(url) + + logger.debug("Saving dno file") + dno_shapes.to_file(dno_local_file) + + +def download_gsp(): + """Down GSP data from NG.""" + + logger.debug("Getting gsp file") + + url = ( + "https://data.nationalgrideso.com/backend/dataset/2810092e-d4b2-472f-b955-d8bea01f9ec0/" + "resource/08534dae-5408-4e31-8639-b579c8f1c50b/download/gsp_regions_20220314.geojson" + ) + ssl._create_default_https_context = ssl._create_unverified_context + gsp_shapes = gpd.read_file(url) + + logger.debug("Saving gsp file") + gsp_shapes.to_file(gsp_local_file) + +# download_dno() +# download_gsp() diff --git a/tests/conftest.py b/tests/conftest.py index 0e114d6..bff5a3b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,7 +11,7 @@ from pvsite_datamodel import GenerationSQL, SiteSQL, StatusSQL from pvsite_datamodel.sqlmodels import Base -from pvsite_datamodel.write.user_and_site import make_site_group, make_user +from pvsite_datamodel.write.user_and_site import create_site_group, create_user @pytest.fixture(scope="session") @@ -80,8 +80,10 @@ def sites(db_session): def user_with_sites(db_session, sites): """Create a user with sites""" - site_group = make_site_group(db_session=db_session) - user = make_user(db_session=db_session, email="test_user@gmail.com", site_group=site_group) + site_group = create_site_group(db_session=db_session) + user = create_user( + session=db_session, email="test_user@gmail.com", site_group_name=site_group.site_group_name + ) site_group.sites = sites return user diff --git a/tests/test_delete.py b/tests/test_delete.py index 50eeca1..ca06459 100644 --- a/tests/test_delete.py +++ b/tests/test_delete.py @@ -2,12 +2,12 @@ from pvsite_datamodel.sqlmodels import SiteSQL, UserSQL from pvsite_datamodel.write.user_and_site import ( + create_site_group, + create_user, delete_site, delete_site_group, delete_user, - make_site, - make_site_group, - make_user, + make_fake_site, ) @@ -15,11 +15,11 @@ def test_delete_site(db_session): """Test to delete a site.""" - site_1 = make_site(db_session=db_session, ml_id=1) + site_1 = make_fake_site(db_session=db_session, ml_id=1) # todo add site to site group - site_group = make_site_group(db_session=db_session, site_group_name="test_site_group") + site_group = create_site_group(db_session=db_session, site_group_name="test_site_group") site_group.sites.append(site_1) site_uuid = site_1.site_uuid @@ -35,12 +35,12 @@ def test_delete_site(db_session): def test_delete_user(db_session): """Test to delete a user.""" - site_group_1 = make_site_group(db_session=db_session) + site_group_1 = create_site_group(db_session=db_session) - user_1 = make_user( - db_session=db_session, + user_1 = create_user( + session=db_session, email="test_user@ocf.org", - site_group=site_group_1, + site_group_name=site_group_1.site_group_name, ) message = delete_user(session=db_session, email=user_1.email) @@ -55,7 +55,7 @@ def test_delete_user(db_session): def test_delete_site_group(db_session): - site_group = make_site_group(db_session=db_session, site_group_name="test_site_group") + site_group = create_site_group(db_session=db_session, site_group_name="test_site_group") message = delete_site_group(session=db_session, site_group_name=site_group.site_group_name) @@ -68,12 +68,12 @@ def test_delete_site_group(db_session): def test_delete_site_group_with_users(db_session): """Test to delete a site group with users.""" - site_group_1 = make_site_group(db_session=db_session) + site_group_1 = create_site_group(db_session=db_session) - _ = make_user( - db_session=db_session, + _ = create_user( + session=db_session, email="test_user@gmail.com", - site_group=site_group_1, + site_group_name=site_group_1.site_group_name, ) message = delete_site_group(session=db_session, site_group_name=site_group_1.site_group_name) diff --git a/tests/test_models.py b/tests/test_models.py index 7e033a8..42192cb 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,4 +1,4 @@ -from pvsite_datamodel.write.user_and_site import make_site, make_site_group, make_user +from pvsite_datamodel.write.user_and_site import create_site_group, create_user, make_fake_site def test_one_site_one_user(db_session): @@ -6,9 +6,11 @@ def test_one_site_one_user(db_session): 1. Test that one site with one user works """ - site_group = make_site_group(db_session=db_session) - one_site = make_site(db_session=db_session) - user = make_user(db_session=db_session, email="test_user@gmail.com", site_group=site_group) + site_group = create_site_group(db_session=db_session) + one_site = make_fake_site(db_session=db_session) + user = create_user( + session=db_session, email="test_user@gmail.com", site_group_name=site_group.site_group_name + ) # add site to site group site_group.sites.append(one_site) @@ -21,10 +23,12 @@ def test_two_site_one_user(db_session): 2. Test that one site with one user works """ - site_group = make_site_group(db_session=db_session) - site_1 = make_site(db_session=db_session, ml_id=1) - site_2 = make_site(db_session=db_session, ml_id=2) - user = make_user(db_session=db_session, email="test_user@gmail.com", site_group=site_group) + site_group = create_site_group(db_session=db_session) + site_1 = make_fake_site(db_session=db_session, ml_id=1) + site_2 = make_fake_site(db_session=db_session, ml_id=2) + user = create_user( + session=db_session, email="test_user@gmail.com", site_group_name=site_group.site_group_name + ) # add site to site group site_group.sites.append(site_1) @@ -38,10 +42,18 @@ def test_one_site_two_user(db_session): 3. Test that one site with two users works """ - site_group = make_site_group(db_session=db_session) - site_1 = make_site(db_session=db_session, ml_id=1) - user_1 = make_user(db_session=db_session, email="test_user_1@gmail.com", site_group=site_group) - user_2 = make_user(db_session=db_session, email="test_user_2@gmail.com", site_group=site_group) + site_group = create_site_group(db_session=db_session) + site_1 = make_fake_site(db_session=db_session, ml_id=1) + user_1 = create_user( + session=db_session, + email="test_user_1@gmail.com", + site_group_name=site_group.site_group_name, + ) + user_2 = create_user( + session=db_session, + email="test_user_2@gmail.com", + site_group_name=site_group.site_group_name, + ) # add site to site group site_group.sites.append(site_1) @@ -55,11 +67,19 @@ def test_two_site_two_user(db_session): 4. Test that has two site with two users """ - site_group = make_site_group(db_session=db_session) - site_1 = make_site(db_session=db_session, ml_id=1) - site_2 = make_site(db_session=db_session, ml_id=2) - user_1 = make_user(db_session=db_session, email="test_user_1@gmail.com", site_group=site_group) - user_2 = make_user(db_session=db_session, email="test_user_2@gmail.com", site_group=site_group) + site_group = create_site_group(db_session=db_session) + site_1 = make_fake_site(db_session=db_session, ml_id=1) + site_2 = make_fake_site(db_session=db_session, ml_id=2) + user_1 = create_user( + session=db_session, + email="test_user_1@gmail.com", + site_group_name=site_group.site_group_name, + ) + user_2 = create_user( + session=db_session, + email="test_user_2@gmail.com", + site_group_name=site_group.site_group_name, + ) # add site to site group site_group.sites.append(site_1) @@ -74,15 +94,25 @@ def test_three_site_two_user_and_ocf_see_everything(db_session): 5. Test that three site with two user works """ - site_group = make_site_group(db_session=db_session) - site_group_ocf = make_site_group(db_session=db_session, site_group_name="OCF") - site_1 = make_site(db_session=db_session, ml_id=1) - site_2 = make_site(db_session=db_session, ml_id=2) - site_3 = make_site(db_session=db_session, ml_id=3) - user_1 = make_user(db_session=db_session, email="test_user_1@gmail.com", site_group=site_group) - user_2 = make_user(db_session=db_session, email="test_user_2@gmail.com", site_group=site_group) - user_ocf = make_user( - db_session=db_session, email="test_user_ocf@gmail.com", site_group=site_group_ocf + site_group = create_site_group(db_session=db_session) + site_group_ocf = create_site_group(db_session=db_session, site_group_name="OCF") + site_1 = make_fake_site(db_session=db_session, ml_id=1) + site_2 = make_fake_site(db_session=db_session, ml_id=2) + site_3 = make_fake_site(db_session=db_session, ml_id=3) + user_1 = create_user( + session=db_session, + email="test_user_1@gmail.com", + site_group_name=site_group.site_group_name, + ) + user_2 = create_user( + session=db_session, + email="test_user_2@gmail.com", + site_group_name=site_group.site_group_name, + ) + user_ocf = create_user( + session=db_session, + email="test_user_ocf@gmail.com", + site_group_name=site_group_ocf.site_group_name, ) # add site to site group diff --git a/tests/test_read.py b/tests/test_read.py index b336122..292b6c2 100644 --- a/tests/test_read.py +++ b/tests/test_read.py @@ -31,7 +31,7 @@ get_sites_from_user, get_user_by_email, ) -from pvsite_datamodel.write.user_and_site import make_site_group, make_user +from pvsite_datamodel.write.user_and_site import create_site_group, create_user class TestGetAllSites: @@ -96,9 +96,13 @@ def test_get_user_by_email_no_users(self, db_session): assert len(db_session.query(UserSQL).all()) == 1 def test_get_user_by_email_with_users(self, db_session): - site_group = make_site_group(db_session=db_session) - user = make_user(db_session=db_session, site_group=site_group, email="test_1@test.com") - user = make_user(db_session=db_session, site_group=site_group, email="test_2@test.com") + site_group = create_site_group(db_session=db_session) + user = create_user( + session=db_session, site_group_name=site_group.site_group_name, email="test_1@test.com" + ) + user = create_user( + session=db_session, site_group_name=site_group.site_group_name, email="test_2@test.com" + ) user = get_user_by_email(session=db_session, email="test_1@test.com") assert user.email == "test_1@test.com" @@ -116,8 +120,10 @@ def test_returns_all_generations_without_input_user(self, generations, db_sessio def test_returns_all_generations_for_input_user(self, generations, db_session): # associate site to one user site: SiteSQL = db_session.query(SiteSQL).first() - site_group = make_site_group(db_session=db_session) - user = make_user(db_session=db_session, site_group=site_group, email="test@test.com") + site_group = create_site_group(db_session=db_session) + user = create_user( + session=db_session, site_group_name=site_group.site_group_name, email="test@test.com" + ) site_group.sites.append(site) generations = get_pv_generation_by_user_uuids( @@ -129,8 +135,10 @@ def test_returns_all_generations_for_input_user(self, generations, db_session): def test_returns_all_generations_in_datetime_window(self, generations, db_session): # associate site to one user site: SiteSQL = db_session.query(SiteSQL).first() - site_group = make_site_group(db_session=db_session) - user = make_user(db_session=db_session, site_group=site_group, email="test@test.com") + site_group = create_site_group(db_session=db_session) + user = create_user( + session=db_session, site_group_name=site_group.site_group_name, email="test@test.com" + ) site_group.sites.append(site) window_lower: dt.datetime = dt.datetime.now(dt.timezone.utc) - dt.timedelta(minutes=7) diff --git a/tests/test_write.py b/tests/test_write.py index 80faf6f..16ab45d 100644 --- a/tests/test_write.py +++ b/tests/test_write.py @@ -12,10 +12,10 @@ from pvsite_datamodel.write.user_and_site import ( add_site_to_site_group, change_user_site_group, + create_site, + create_site_group, create_user, - make_site, - make_site_group, - make_user, + make_fake_site, ) @@ -59,57 +59,56 @@ def test_inserts_generation_duplicates(self, db_session, generation_valid_site): assert db_session.query(GenerationSQL).count() == 10 -# # create new site, this will be one in a different issue -# def test_create_new_site(db_session): -# site, message = create_new_site( -# session=db_session, -# client_site_id=6932, -# client_site_name="test_site_name", -# latitude=1.0, -# longitude=1.0, -# capacity_kw=1.0, -# ) - -# assert site.client_site_name == "test_site_name" -# assert site.ml_id == 1 -# assert site.client_site_id == 6932 -# assert ( -# message -# == f"Site with client site id {site.client_site_id} -# and site uuid {site.site_uuid} created successfully" -# ) - - -# # test for create_new_site to check ml_id increments -# def test_create_new_site_twice(db_session): -# """Test create new site function for ml_id""" - -# site_1, _ = create_new_site( -# session=db_session, -# client_site_id=6932, -# client_site_name="test_site_name", -# latitude=1.0, -# longitude=1.0, -# capacity_kw=1.0, -# ) - -# site_2, _ = create_new_site( -# session=db_session, -# client_site_id=6932, -# client_site_name="test_site_name", -# latitude=1.0, -# longitude=1.0, -# capacity_kw=1.0, -# ) - -# assert site_1.ml_id == 1 -# assert site_2.ml_id == 2 +# create new site, this will be one in a different issue +def test_create_new_site(db_session): + site, message = create_site( + session=db_session, + client_site_id=6932, + client_site_name="test_site_name", + latitude=51.0, + longitude=0.0, + capacity_kw=1.0, + ) + + assert site.client_site_name == "test_site_name" + assert site.ml_id == 1 + assert site.client_site_id == 6932 + assert ( + message == f"Site with client site id {site.client_site_id} " + f"and site uuid {site.site_uuid} created successfully" + ) + + +# test for create_new_site to check ml_id increments +def test_create_new_site_twice(db_session): + """Test create new site function for ml_id""" + + site_1, _ = create_site( + session=db_session, + client_site_id=6932, + client_site_name="test_site_name", + latitude=1.0, + longitude=1.0, + capacity_kw=1.0, + ) + + site_2, _ = create_site( + session=db_session, + client_site_id=6932, + client_site_name="test_site_name", + latitude=1.0, + longitude=1.0, + capacity_kw=1.0, + ) + + assert site_1.ml_id == 1 + assert site_2.ml_id == 2 def test_create_user(db_session): "Test to create a new user." - site_group_1 = make_site_group(db_session=db_session) + site_group_1 = create_site_group(db_session=db_session) user_1 = create_user( session=db_session, @@ -124,10 +123,10 @@ def test_create_user(db_session): # add site to site group def test_add_site_to_site_group(db_session): - site_group = make_site_group(db_session=db_session) - site_1 = make_site(db_session=db_session, ml_id=1) - site_2 = make_site(db_session=db_session, ml_id=2) - site_3 = make_site(db_session=db_session, ml_id=3) + site_group = create_site_group(db_session=db_session) + site_1 = make_fake_site(db_session=db_session, ml_id=1) + site_2 = make_fake_site(db_session=db_session, ml_id=2) + site_3 = make_fake_site(db_session=db_session, ml_id=3) site_group.sites.append(site_1) site_group.sites.append(site_2) @@ -144,9 +143,11 @@ def test_add_site_to_site_group(db_session): def test_change_user_site_group(db_session): """Test the change user site group function :param db_session: the database session""" - site_group = make_site_group(db_session=db_session) - user = make_user(db_session=db_session, email="test_user@gmail.com", site_group=site_group) - site_group2 = make_site_group(db_session=db_session, site_group_name="test_site_group2") + site_group = create_site_group(db_session=db_session) + user = create_user( + session=db_session, email="test_user@gmail.com", site_group_name=site_group.site_group_name + ) + site_group2 = create_site_group(db_session=db_session, site_group_name="test_site_group2") user, user_site_group = change_user_site_group( session=db_session, email="test_user@gmail.com",