Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions templates/childrensuspectwarning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from ast import Str
from collections.abc import Callable
from xmlrpc.client import Boolean
from valispace import API
import warnings
import time

VALISPACE = {
'domain': 'https://demonstration.valispace.com/',
'username': 'AutomationsAPI',
'password': 'AutomationsAPI'
}

DEFAULT_VALUES = {
"project": 24,
}


def get_map(api: API, endpoint: Str = "/", name: Str = "id", name_map_func: Callable[[Str], Boolean] = None, filter_func: Callable[[Str], Boolean]= None):
"""
Function that given an endpoint returns a dict with specific keys.
If function is provided it generates the key. name_map_func must receive an object instance.
Otherwise key will be the property of each object specified in name.
"""
mapping = {}
if not name_map_func:
name_map_func = lambda x: x[name]
for inst in api.get(endpoint):
if filter_func and not filter_func(inst):
# Filtered out
continue

key = name_map_func(inst)
if not mapping.get(key):
mapping[key] = inst
else:
warnings.warn(f"Warning ---> Key: {key} already has an object. Some data may be lost in mapping.")
return mapping


def main(**kwargs):

api = API(
url = VALISPACE.get('domain'),
username = VALISPACE.get('username'),
password = VALISPACE.get('password'),
warn_https = VALISPACE.get('warn_https', False),
)

all_deployment_users = get_map(api, f"user/", "id")

requirement_data = kwargs['triggered_objects'][0]

#requirement_data = api.get('requirements/81') #just for testing now without automation to receive the trigger object
print(requirement_data)
time.sleep(15)

user_changing_req = all_deployment_users[requirement_data['updated_by']]
username = user_changing_req['first_name']+" "+user_changing_req['last_name']
user = f"<span class=\"quill-autocomplete\" host=\"user\" itemid=\"{user_changing_req['id']}\" name=\"{username}\" field=\"displayName\"><user editable=\"true\" itemid=\"{user_changing_req['id']}\" field=\"displayName\">@{username}</user></span>"
requirement = f"<span class=\"quill-autocomplete\" host=\"requirement\" itemid=\"{requirement_data['id']}\" name=\"{requirement_data['identifier']}\" field=\"identifier\"><requirement editable=\"true\" itemid=\"{requirement_data['id']}\" field=\"identifier\">${requirement_data['identifier']}</requirement></span>"

print(requirement_data["children"])
req_children = requirement_data["children"]
if len(req_children)>0:
for children in req_children:

discussionData = {
"title" : user + " -> Parent of "+ requirement + " was updated",
"project": DEFAULT_VALUES["project"],
"content_type" : 120,
"group": 1,
"object_id": children,
}
createdDiscussion = api.post('discussions/', data=discussionData)

print("Discussions created for each Children")

pass

if __name__=='__main__':
main()
50 changes: 50 additions & 0 deletions templates/newtask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from valispace import API
from datetime import datetime, timedelta



VALISPACE = {
'domain': 'https://demonstration.valispace.com/',
'username': 'AutomationsAPI',
'password': 'AutomationsAPI'
}

DEFAULT_VALUES = {
"project": 24,
"start_date": "",
"today_date": ""
}

def main(**kwargs):

api = API(
url = VALISPACE.get('domain'),
username = VALISPACE.get('username'),
password = VALISPACE.get('password')
)
DEFAULT_VALUES["start_date"] = api.get('project/'+str(DEFAULT_VALUES["project"]))['start_date']
DEFAULT_VALUES["today_date"] = datetime.now().strftime("%Y-%m-%d")
print (DEFAULT_VALUES["today_date"])
print(kwargs)

#object_id = triggers[0]['id']

taskData = {
"title" : "testing Task Creation",
"project": DEFAULT_VALUES["project"],
"description" : "this is the description of the testing tasks",
"duration" : 5,
"duration_unit" : "days",
"start_date" : DEFAULT_VALUES["today_date"],
"content_type" : 38,
#"object_id": object_id,
"object_id": 13700,
"public" : True
}
createdTask = api.post('user-tasks/', data=taskData)
updatedTask = api.request('PUT', 'user-tasks/'+str(createdTask['id'])+"/add-member/", data={"member": "5"})

pass

if __name__=='__main__':
main()
124 changes: 124 additions & 0 deletions templates/requirementstats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import csv, json
from valispace import API

import warnings
import os
import urllib.request
import time

from ast import Str
from collections.abc import Callable
from xmlrpc.client import Boolean

VALISPACE = {
'domain': 'https://demonstration.valispace.com/',
'username': 'AutomationsAPI',
'password': 'AutomationsAPI'
}

DEFAULT_VALUES = {
"project": 24,
}

def get_map(api: API, endpoint: Str = "/", name: Str = "id", name_map_func: Callable[[Str], Boolean] = None, filter_func: Callable[[Str], Boolean]= None):
"""
Function that given an endpoint returns a dict with specific keys.
If function is provided it generates the key. name_map_func must receive an object instance.
Otherwise key will be the property of each object specified in name.
"""
mapping = {}
if not name_map_func:
name_map_func = lambda x: x[name]
for inst in api.get(endpoint):
if filter_func and not filter_func(inst):
# Filtered out
continue

key = name_map_func(inst)
if not mapping.get(key):
mapping[key] = inst
else:
warnings.warn(f"Warning ---> Key: {key} already has an object. Some data may be lost in mapping.")
return mapping

def main(**kwargs):

api = API(
url = VALISPACE.get('domain'),
username = VALISPACE.get('username'),
password = VALISPACE.get('password')
)

all_project_requirements = get_map(api, f"requirements/complete/?project="+str(DEFAULT_VALUES["project"]), "id")

nr_reqs = 0 #15093
nr_req_w_children = 0 #15094
nr_req_w_vm = 0 #15095
nr_req_vm_analysis = 0 #15099
nr_req_vm_review = 0 #15100
nr_req_vm_inspection = 0 #15101
nr_req_vm_rules = 0 #15102
nr_req_vm_tests = 0 #15103
nr_req_state_draft = 0 #15096
nr_req_state_in_review = 0 #15097
nr_req_state_final = 0 #15098
nr_req_verified = 0 #15104
nr_req_not_verified = 0 #15105

nr_reqs = len(all_project_requirements)

for requirement in all_project_requirements:
req_data=all_project_requirements[requirement]

if req_data['verified'] == True:
nr_req_verified += 1
elif req_data['verified'] == False:
nr_req_not_verified += 1

if req_data['total_children'] != 0:
nr_req_w_children += 1

if req_data['state'] == 7: #but for other projects we need to get by state name
nr_req_state_draft += 1
elif req_data['state'] == 8:
nr_req_state_in_review += 1
elif req_data['state'] == 9:
nr_req_state_final += 1

if req_data['verification_methods'] != None:
nr_req_w_vm += 1
for vm in req_data['verification_methods'] :
if vm['method'] != None:
vm_name = vm['method']['name']
if vm_name == "Analysis":
nr_req_vm_analysis += 1
elif vm_name == "Inspection":
nr_req_vm_inspection += 1
elif vm_name == "Review":
nr_req_vm_review += 1
elif vm_name == "Rules":
nr_req_vm_rules += 1
elif vm_name == "Test":
nr_req_vm_tests += 1

print("going to patch")
time.sleep(15)

api.request("patch", "valis/15093/", data={"formula":nr_reqs})
api.request("patch", "valis/15094/", data={"formula":nr_req_w_children})
api.request("patch", "valis/15095/", data={"formula":nr_req_w_vm})
api.request("patch", "valis/15096/", data={"formula":nr_req_state_draft})
api.request("patch", "valis/15097/", data={"formula":nr_req_state_in_review})
api.request("patch", "valis/15098/", data={"formula":nr_req_state_final})
api.request("patch", "valis/15099/", data={"formula":nr_req_vm_analysis})
api.request("patch", "valis/15100/", data={"formula":nr_req_vm_review})
api.request("patch", "valis/15101/", data={"formula":nr_req_vm_inspection})
api.request("patch", "valis/15102/", data={"formula":nr_req_vm_rules})
api.request("patch", "valis/15103/", data={"formula":nr_req_vm_tests})
api.request("patch", "valis/15104/", data={"formula":nr_req_verified})
api.request("patch", "valis/15105/", data={"formula":nr_req_not_verified})

pass

if __name__=='__main__':
main()
34 changes: 34 additions & 0 deletions templates/simpleconnectiontest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from valispace import API
from datetime import datetime, timedelta
import time

VALISPACE = {
'domain': 'https://demonstration.valispace.com/',
'username': 'AutomationsAPI',
'password': 'AutomationsAPI'
}

DEFAULT_VALUES = {
"project": 24,
"start_date": "",
"today_date": ""
}

def main(**kwargs):

api = API(
url = VALISPACE.get('domain'),
username = VALISPACE.get('username'),
password = VALISPACE.get('password')
#warn_https=False
)
DEFAULT_VALUES["start_date"] = api.get('project/'+str(DEFAULT_VALUES["project"]))['start_date']
DEFAULT_VALUES["today_date"] = datetime.now().strftime("%Y-%m-%d")
print (DEFAULT_VALUES["today_date"])
time.sleep(60)
print(kwargs)

pass

if __name__=='__main__':
main()
41 changes: 41 additions & 0 deletions templates/simulations/electronicpressureregulator.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function [response] = main(data)
%% This is the first function to be called when executing the script
% -----------------------------------------------------------------
% Data: Scalar structure with data comming from Valispace.
%
% Example of use:
% mass = data.mass
% ------------------------------------------------------------------
% Response: Scalar structure with data to send to Valispace.
%
% Example of use:
% response = struct()
% response.total_mass = data.mass * 10
% response.double_mass = data.mass * 2
% ------------------------------------------------------------------

% Get inputs from Valispace
P_in = data.P_in;
V_in = data.V_in;

% Previous code from simulation
V_in = 1.2 ;
F_1 = 25 ;
PV_1 = P_in*V_in;
m_dot = 6;
density = 5.761;
A_inlet = m_dot / (density*V_in);
A_2 = A_inlet/2.5;
m_dot2 = 5;
V_2 = m_dot2/(density*A_2);
P_2 = PV_1/V_2;
A_orifice = F_1/P_2;
PV_2 = P_2*V_2;
V_out = 70.58882;
Pout = PV_2/V_out;

% Send outputs back to Valispace
response = struct()
response.Pout = Pout;

end
25 changes: 25 additions & 0 deletions templates/simulations/electronicpressureregulator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pathlib import Path
from typing import Dict, Any
import oct2py # pylint: disable=import-error


def main(**kwargs) -> Dict[str, Any]:
"""
This is the main function to execute your script and it must exists.
You shouldn't modify this function unless you are familiar with oct2py.

Other functions and files can be also created. You have at your disposal
to import Valispace API, oct2py, scipy, numpy and pint.

:param kwargs: Dictionary with data received from Valispace.
:type kwargs: Dict[str, Any]

:return: Dictionary with data to send back to Valispace.
:rtype: Dict[str, Any]
"""
# Initialize octave and add all .m files to octave
octave = oct2py.Oct2Py()
octave.addpath(str(Path(__file__).resolve().parent))

# Run main function from main.m and send response back to Valispace
return octave.main(kwargs)
Loading