Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/portable_app_framework/__init__.py
  • Loading branch information
Giudice7 committed Feb 19, 2024
2 parents ef1767d + 1f1dc9e commit d5783f2
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 38 deletions.
75 changes: 37 additions & 38 deletions src/portable_app_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Application:
Application class
"""

def __init__(self, metadata=None, app_name=None):
def __init__(self, data=None, metadata=None, app_name=None):
# Class specific logger
self.logger = CustomLogger().get_logger()
# The graph_path and datasource are external to the configuration file.
Expand All @@ -72,8 +72,7 @@ def __init__(self, metadata=None, app_name=None):
self.data_internal = None
self.res = {}
self.mapping = None
# TODO: Path to application in the init input
self.path_to_app = os.path.abspath(os.path.join('app', app_name))
self.path_to_app = os.path.join(USER_BASEPATH, APP_FOLDER, app_name)

'''
The config folder should be structured as follows
Expand All @@ -100,6 +99,7 @@ def __init__(self, metadata=None, app_name=None):
else:
config_file = load_file(os.path.join(USER_BASEPATH, APP_FOLDER, app_name, 'config.yaml'), yaml_type=True)
self.details = config_file['details']
self.parameters = config_file['parameters']
self.manifest = os.path.join(USER_BASEPATH, APP_FOLDER, app_name, 'manifest.ttl')
self.query = load_file(os.path.join(USER_BASEPATH, APP_FOLDER, app_name, 'query.rq'))

Expand Down Expand Up @@ -288,36 +288,36 @@ def cli_new_app():
update_readme(answer["name"])


def cli_clone_app():
"""
Create new application from template
"""
app_names = [app for app in os.listdir(os.path.dirname(__file__)) if app.startswith('app')]

questions = [
inquirer.List(
"app",
message="Which app do you want to clone?",
choices=app_names,
),
]

answer = inquirer.prompt(questions)
print(answer)
# copy folder app_example to app_name
os.system(
f'cp -r {os.path.join(MODULE_BASEPATH, answer["app"])} {os.path.join(USER_BASEPATH, APP_FOLDER, answer["app"])}')


def cli_list_app():
"""
List available applications excluding example
"""
# list folders in app folder inside the module
app_folder = os.listdir(MODULE_BASEPATH)
# list only folders that start with ap
app_names = [app for app in app_folder if app.startswith('app')]
print(app_names)
# def cli_clone_app():
# """
# Create new application from template
# """
# app_names = [app for app in os.listdir(os.path.dirname(__file__)) if app.startswith('app')]
#
# questions = [
# inquirer.List(
# "app",
# message="Which app do you want to clone?",
# choices=app_names,
# ),
# ]
#
# answer = inquirer.prompt(questions)
# print(answer)
# # copy folder app_example to app_name
# os.system(
# f'cp -r {os.path.join(MODULE_BASEPATH, answer["app"])} {os.path.join(USER_BASEPATH, APP_FOLDER, answer["app"])}')


# def cli_list_app():
# """
# List available applications excluding example
# """
# # list folders in app folder inside the module
# app_folder = os.listdir(MODULE_BASEPATH)
# # list only folders that start with ap
# app_names = [app for app in app_folder if app.startswith('app')]
# print(app_names)


def update_readme(app_name):
Expand All @@ -339,14 +339,14 @@ def update_readme(app_name):
md += f'The app[^1] is structured as follows:\n\n'
md += f'- Configuration file ([config.yaml](config.yaml))\n'
md += f'- SPARQL query ([query.rq](query.rq))\n'
md += f'- SHACL Shape or manifest ([manifest.ttl](manifest.ttl))\n\n\n'
md += f'- Clean function ([clean.py](clean.py))\n\n\n'
md += f'- SHACL Shape or manifest ([manifest.ttl](manifest.ttl))\n'
md += f'- Clean function ([clean.py](clean.py))\n'
md += f'- Analyze function ([analyze.py](analyze.py))\n\n\n'
md += f'## Usage\n\n'
md += f'```python\n'
md += f'import pandas as pd\n'
md += f'import brickschema\n'
md += f'from portable-app-framework import Application\n\n' # todo dare nome migliore a pacchetto
md += f'from portable_app_framework import Application\n\n' # todo dare nome migliore a pacchetto
md += f'app = Application(\n'
md += f' data=pd.DataFrame(),\n'
md += f' metadata=brickschema.Graph(),\n'
Expand All @@ -373,13 +373,12 @@ def cli_update_app():
name="app",
message="Which app do you want to update?",
choices=["all"] + app_names,
default=["all"]
)
]
# todo add validation on empty

answer = inquirer.prompt(questions)

print(answer)
if len(answer['app']) > 1:
for app in answer['app']:
update_readme(app)
Expand Down
16 changes: 16 additions & 0 deletions src/portable_app_framework/app_template/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@ details:
email: example@mail.com
created_at: YYYY-MM-DD

parameters:
time_from:
value: 2021-01-01T00:00:00Z
description: The starting time for the analysis
type: string
time_to:
value: 2021-01-01T00:00:00Z
description: The ending time for the analysis
type: string
aggregation:
value: 1h
description: The aggregation level for the analysis
type: string



35 changes: 35 additions & 0 deletions test/app/app_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[//]: # (AUTOMATICALLY GENERATED DO NOT MODIFY)

# App Template

#### Version v.1.0 (YYYY-MM-DD)

Short description

## Structure

The app[^1] is structured as follows:

- Configuration file ([config.yaml](config.yaml))
- SPARQL query ([query.rq](query.rq))
- SHACL Shape or manifest ([manifest.ttl](manifest.ttl))

## Usage

```python
import pandas as pd
import brickschema
from portable_app_framework import Application

app = Application(
data=pd.DataFrame(),
metadata=brickschema.Graph(),
app_name='app_template'
)
app.qualify()
app.fetch()
app.clean()
app.analyze()
```

[^1]: by Author Name - example@mail.com
Empty file added test/app/app_test/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions test/app/app_test/analyze.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def analyze_fn():
pass
2 changes: 2 additions & 0 deletions test/app/app_test/clean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def clean_fn():
pass
24 changes: 24 additions & 0 deletions test/app/app_test/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
details:
name: App name
description: Short description
version: 1.0
author: Author Name
email: example@mail.com
created_at: YYYY-MM-DD

parameters:
time_from:
value: 2021-01-01T00:00:00Z
description: The starting time for the analysis
type: string
time_to:
value: 2021-01-01T00:00:00Z
description: The ending time for the analysis
type: string
aggregation:
value: 1h
description: The aggregation level for the analysis
type: string



8 changes: 8 additions & 0 deletions test/app/app_test/manifest.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@prefix brick: <https://brickschema.org/schema/Brick#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix constraint: <https://nrel.gov/BuildingMOTIF/constraints#> .
@prefix : <urn:my_site_constraints/> .

:
a owl:Ontology .
6 changes: 6 additions & 0 deletions test/app/app_test/query.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX brick: <https://brickschema.org/schema/Brick#>
PREFIX bldg: <http://bldg-59#>
SELECT *
WHERE {
}
151 changes: 151 additions & 0 deletions test/data/test.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
@prefix bldg: <http://bldg-59#> .
@prefix brick: <https://brickschema.org/schema/Brick#> .

bldg:AHU
a brick:AHU ;
brick:feeds bldg:Zone_1, bldg:Zone_2, bldg:Zone_3, bldg:Zone_4, bldg:Zone_5 ;
brick:hasPart bldg:Cooling_Coil, bldg:Outdoor_Air_Damper, bldg:Return_Air_Damper, bldg:Return_Air_Fan,
bldg:Supply_Air_Fan ;
brick:hasPoint bldg:MA_TEMP, bldg:OA_CFM, bldg:OA_TEMP, bldg:RA_CFM, bldg:RA_TEMP, bldg:SA_CFM, bldg:SA_SP,
bldg:SA_SPSPT, bldg:SA_TEMP, bldg:SA_TEMPSPT, bldg:SYS_CTL .

bldg:CHWC_VLV
a brick:Valve_Position_Sensor .

bldg:CHWC_VLV_DM
a brick:Valve_Position_Command .

#bldg:Cooling_Coil
# a brick:Chilled_Water_Coil ;
# brick:hasPoint bldg:CHWC_VLV, bldg:CHWC_VLV_DM .

bldg:Cooling_Coil
a brick:Cooling_Coil ; # changed in Cooling_Coil https://brickschema.org/ontology/Nightly/classes/Cooling_Coil
brick:hasPoint bldg:CHWC_VLV, bldg:CHWC_VLV_DM .

bldg:MA_TEMP
a brick:Mixed_Air_Temperature_Sensor .

bldg:OA_CFM
a brick:Outside_Air_Flow_Sensor .

bldg:OA_DMPR
a brick:Damper_Position_Sensor .

bldg:OA_DMPR_DM
a brick:Damper_Position_Command .

bldg:OA_TEMP
a brick:Outside_Air_Temperature_Sensor .

bldg:Outdoor_Air_Damper
a brick:Outside_Damper ;
brick:hasPoint bldg:OA_DMPR, bldg:OA_DMPR_DM .

bldg:RA_CFM
a brick:Return_Air_Flow_Sensor .

bldg:RA_DMPR
a brick:Damper_Position_Sensor .

bldg:RA_DMPR_DM
a brick:Damper_Position_Command .

bldg:RA_TEMP
a brick:Return_Air_Temperature_Sensor .

bldg:RF_CS
a brick:Speed_Setpoint .

bldg:RF_SPD
a brick:Speed_status .

bldg:RF_SPD_DM
a brick:Fan_On_Off_Status .

bldg:RF_WAT
a brick:Electrical_Power_Sensor .

bldg:Return_Air_Damper
a brick:Return_Damper ;
brick:hasPoint bldg:RA_DMPR, bldg:RA_DMPR_DM .

#bldg:Return_Air_Fan
# a brick:Fan ;
# brick:hasPoint bldg:RF_CS, bldg:RF_SPD, bldg:RF_SPD_DM, bldg:RF_WAT .
bldg:Return_Air_Fan
a brick:Return_Fan ; # changed in Return_Fan
brick:hasPoint bldg:RF_CS, bldg:RF_SPD, bldg:RF_SPD_DM, bldg:RF_WAT .

bldg:SA_CFM
a brick:Supply_Air_Flow_Sensor .

bldg:SA_SP
a brick:Supply_Air_Static_Pressure_Sensor .

bldg:SA_SPSPT
a brick:Supply_Air_Static_Pressure_Setpoint .

bldg:SA_TEMP
a brick:Supply_Air_Temperature_Sensor .

bldg:SA_TEMPSPT
a brick:Supply_Air_Temperature_Setpoint .

bldg:SF_CS
a brick:Speed_Setpoint .

bldg:SF_SPD
a brick:Speed_status .

bldg:SF_SPD_DM
a brick:Fan_On_Off_Status .

bldg:SF_WAT
a brick:Electrical_Power_Sensor .

bldg:SYS_CTL
a brick:Occupancy_Status .

#bldg:Supply_Air_Fan
# a brick:Fan ;
# brick:hasPoint bldg:SF_CS, bldg:SF_SPD, bldg:SF_SPD_DM, bldg:SF_WAT .
bldg:Supply_Air_Fan
a brick:Supply_Fan ; ## changed fan into Supply_Fan
brick:hasPoint bldg:SF_CS, bldg:SF_SPD, bldg:SF_SPD_DM, bldg:SF_WAT .

bldg:ZONE_TEMP_1
a brick:Zone_Air_Temperature_Sensor .

bldg:ZONE_TEMP_2
a brick:Zone_Air_Temperature_Sensor .

bldg:ZONE_TEMP_3
a brick:Zone_Air_Temperature_Sensor .

bldg:ZONE_TEMP_4
a brick:Zone_Air_Temperature_Sensor .

bldg:ZONE_TEMP_5
a brick:Zone_Air_Temperature_Sensor .

bldg:Zone_1
a brick:HVAC_Zone ;
brick:hasPoint bldg:ZONE_TEMP_1 .

bldg:Zone_2
a brick:HVAC_Zone ;
brick:hasPoint bldg:ZONE_TEMP_2 .

bldg:Zone_3
a brick:HVAC_Zone ;
brick:hasPoint bldg:ZONE_TEMP_3 .

bldg:Zone_4
a brick:HVAC_Zone ;
brick:hasPoint bldg:ZONE_TEMP_4 .

bldg:Zone_5
a brick:HVAC_Zone ;
brick:hasPoint bldg:ZONE_TEMP_5 .

Loading

0 comments on commit d5783f2

Please sign in to comment.