Commit 68ed0cea authored by Alexander Lercher's avatar Alexander Lercher

Merge branch 'develop' into feature/community-prediction

parents b0499784 877c5e65
......@@ -18,4 +18,10 @@ src/modules/security/default_users.json
resources/
src/dashboard/.dart_tool/
src/dashboard/build/61d113a1f91ed254ee3636485549491e/
src/dashboard/build/
reports/
......@@ -35,6 +35,23 @@ def get_dockerfile_paths_and_names() -> Dict[str, str]:
return command_args
def is_flutter_project(path: str) -> bool:
test_file_path = f"{path}/pubspec.yaml"
return os.path.exists(test_file_path)
class cd:
"""Context manager for changing the current working directory"""
def __init__(self, newPath):
self.newPath = os.path.expanduser(newPath)
def __enter__(self):
self.savedPath = os.getcwd()
os.chdir(self.newPath)
def __exit__(self, etype, value, traceback):
os.chdir(self.savedPath)
if __name__ == '__main__':
p_image_name = None
......@@ -60,6 +77,11 @@ if __name__ == '__main__':
path = command_arg['path']
image_name = f"{DOCKERHUB_REPO_OWNER}/{command_arg['name']}"
if is_flutter_project(path):
with cd(path):
print(f"> flutter build web")
os.system(f"flutter build web")
# copy Dockerfile into root dir to have access to modules folder
shutil.copy2(os.path.join(path, DOCKER_BUILD_NAME), ROOT)
......
......@@ -61,7 +61,7 @@ def delete_deployment(name) -> int:
if __name__ == '__main__':
deployment_file_paths = []
for p, _, f in os.walk('./'):
for p, _, f in os.walk('./src/'):
for file in f:
if 'deployment.yml' == file:
deployment_file_paths.append(os.path.normpath(p))
......
......@@ -24,6 +24,7 @@ This token is used for authentication as _regular user_ on all microservices cur
```
{
"ApplicationType": "use-case identifier as string",
"docType": "use-case-table identifier as string",
"key": "value",
...
}
......@@ -91,4 +92,4 @@ Returns the computed similarity. Two clusters belonging to the SAME layer will b
## Connected Cluster
Intermediary data-structure used only by the function which computes the similarity. Clusters are connected only to other clusters belonging to a DIFFERENT layer.
```GET https://articonf1.itec.aau.at:30103/api/use_cases/{use_case}/tables{table}/connectedClusters``` returns all connected clusters for the given use-case and table.
```GET https://articonf1.itec.aau.at:30103/api/use_cases/{use_case}/tables/{table}/connectedClusters``` returns all connected clusters for the given use-case and table.
FROM python:3
LABEL maintainer="Alexander Lercher"
ENV http_proxy http://proxy.uni-klu.ac.at:3128/
ENV https_proxy http://proxy.uni-klu.ac.at:3128/
LABEL maintainer="Manuel Herold"
RUN apt-get update
RUN pip install flask
......
FROM python:3
LABEL maintainer="Alexander Lercher"
ENV http_proxy http://proxy.uni-klu.ac.at:3128/
ENV https_proxy http://proxy.uni-klu.ac.at:3128/
RUN apt-get update
RUN pip install flask
RUN pip install connexion[swagger-ui]
......
FROM python:3
LABEL maintainer="Alexander Lercher"
ENV http_proxy http://proxy.uni-klu.ac.at:3128/
ENV https_proxy http://proxy.uni-klu.ac.at:3128/
LABEL maintainer="Manuel Herold"
RUN apt-get update
RUN pip install flask
......@@ -11,7 +8,13 @@ RUN pip install connexion[swagger-ui]
EXPOSE 5000
WORKDIR /app
COPY src/data-hub/reputation-calculation-microservice/app/requirements.txt /app/
RUN pip install -r requirements.txt
COPY src/data-hub/reputation-calculation-microservice/app/ /app/
COPY src/modules/ /app/
RUN chmod a+x main.py
CMD ["python", "./main.py"]
\ No newline at end of file
......@@ -11,20 +11,9 @@ produces:
basePath: "/api"
# Import security definitions from seperate file
securityDefinitions:
$ref: '../security/security.yml#securityDefinitions'
paths:
/debug:
post:
operationId: "debug.echo"
tags:
- "Echo"
summary: "Echo function for debugging purposes"
description: "Echoes the input back to the caller."
parameters:
- in: body
name: "Object"
required: true
schema:
type: object
responses:
200:
description: "Successful echo of request data"
$ref: 'routes.yml#paths'
\ No newline at end of file
swagger: "2.0"
info:
title: Reputation Calculation microservice
description: This is the documentation for the reputation calculation microservice.
version: "1.0.0"
consumes:
- "application/json"
produces:
- "application/json"
basePath: "/api"
# Import security definitions from seperate file
securityDefinitions:
$ref: '../../../../modules/security/security_local.yml#securityDefinitions'
paths:
$ref: 'routes.yml#paths'
\ No newline at end of file
from typing import Dict
class Context:
def __init__(self, use_case:str, name:str):
self.use_case = use_case
self.name = name
def to_serializable_dict(self):
return {
"use_case": self.use_case,
"name": self.name
}
@staticmethod
def from_serializable_dict(data: Dict):
if "use_case" not in data.keys() or "name" not in data.keys():
raise ValueError("Missing fields!")
return Context(data["use_case"], data["name"])
\ No newline at end of file
from typing import Dict
class TrustAdapter:
def __init__(self, use_case: str, context: str, table: str, user_source: str, volume_source: str,
rating_source: str, rating_lower: float, rating_upper: float, conversion: float,
certainty: float, cutoff: float, bias_negative: float, bias_positive: float):
self.use_case = use_case
self.context = context
self.table = table
self.user_source = user_source
self.volume_source = volume_source
self.rating_source = rating_source
self.rating_lower = rating_lower
self.rating_upper = rating_upper
self.conversion = conversion
self.certainty = certainty
self.cutoff = cutoff
self.bias_negative = bias_negative
self.bias_positive = bias_positive
def to_serializable_dict(self):
return {
"use_case": self.use_case,
"context": self.context,
"table": self.table,
"user_source": self.user_source,
"volume_source": self.volume_source,
"rating_source": self.rating_source,
"rating_lower": self.rating_lower,
"rating_upper": self.rating_upper,
"conversion": self.conversion,
"certainty": self.certainty,
"cutoff": self.cutoff,
"bias_negative": self.bias_negative,
"bias_positive": self.bias_positive
}
@staticmethod
def from_serializable_dict(data: Dict):
if "use_case" not in data.keys() or "context" not in data.keys() or "table" not in data.keys() or "user_source" not in data.keys() or "volume_source" not in data.keys() or "rating_source" not in data.keys() or "conversion" not in data.keys() or "certainty" not in data.keys() or "cutoff" not in data.keys() or "bias_negative" not in data.keys() or "bias_positive" not in data.keys():
raise ValueError("Missing fields for TrustAdapter!")
return TrustAdapter(
data["use_case"],
data["context"],
data["table"],
data["user_source"],
data["volume_source"],
data["rating_source"],
data["rating_lower"],
data["rating_upper"],
data["conversion"],
data["certainty"],
data["cutoff"],
data["bias_negative"],
data["bias_positive"],
)
from datetime import datetime
from lib.trust.transaction import Transaction
from typing import Dict
class TrustTrace(Transaction):
def __init__(self, use_case: str, context: str, user: str, table: str, volume: float, timestamp: datetime, is_trustworthy: float = 1):
super().__init__(timestamp, volume, is_trustworthy=is_trustworthy)
self.use_case = use_case
self.context = context
self.user = user
self.table = table
def to_serializable_dict(self):
return {
"volume": self.volume,
"trustworthy": self.trustworthy,
"timestamp": self.timestamp.isoformat(),
"use_case": self.use_case,
"context": self.context,
"user": self.user,
"table": self.table,
}
@staticmethod
def from_serializable_dict(data: Dict):
if "volume" not in data.keys() or "trustworthy" not in data.keys() or "timestamp" not in data.keys() or "use_case" not in data.keys() or "context" not in data.keys() or "user" not in data.keys() or "table" not in data.keys():
raise ValueError("Missing fields for User!")
return TrustTrace(
data["use_case"],
data["context"],
data["table"],
data["volume"],
datetime.fromisoformat(data["timestamp"]),
is_trustworthy=data["trustworthy"]
)
from lib.database.entities.user_trust import UserTrust
from datetime import datetime
from typing import Dict, List
class User:
def __init__(self, use_case: str, name: str, context_trust: List[UserTrust] = []):
self.use_case = use_case
self.name = name
self.context_trust = context_trust
def to_serializable_dict(self, include_trust: bool = False):
if include_trust:
return {
"use_case": self.use_case,
"name": self.name,
"context_trust": [t.to_serializable_dict() for t in self.context_trust]
}
else:
return {
"use_case": self.use_case,
"name": self.name
}
@staticmethod
def from_serializable_dict(data: Dict):
if "use_case" not in data.keys() or "name" not in data.keys():
raise ValueError("Missing fields for User!")
return User(data["use_case"], data["name"])
from datetime import datetime
from typing import Dict
class UserTrust:
def __init__(self, use_case: str, context: str, user: str, t: float, last_update: datetime):
self.use_case = use_case
self.context = context
self.user = user
self.t = t
self.last_update = last_update
def to_serializable_dict(self):
return {
"use_case": self.use_case,
"context": self.context,
"user": self.user,
"t": self.t,
"last_update": self.last_update
}
@staticmethod
def from_serializable_dict(data: Dict):
if "use_case" not in data.keys() or "context" not in data.keys() or "user" not in data.keys() or "t" not in data.keys() or "last_update" not in data.keys():
raise ValueError("Missing fields for User!")
return UserTrust(data["use_case"], data["context"], data["user"], data["t"], data["last_update"])
\ No newline at end of file
# global imports (dont't worry, red is normal)
import network_constants as netconst
from database.MongoRepositoryBase import MongoRepositoryBase
from lib.database.entities.context import Context
from typing import List, Dict
class ContextRepository(MongoRepositoryBase):
'''This is a repository for MongoDb.'''
def __init__(self):
super().__init__(netconst.REPUTATION_CALCULATION_DB_HOSTNAME,
netconst.REPUTATION_CALCULATION_DB_PORT,
'reputation-computation-db')
self._collection = 'context'
def add(self, context: Context):
super().insert_entry(self._collection, context.to_serializable_dict())
def all(self) -> List[Dict]:
result = super().get_entries(self._collection, projection={'_id': False})
return list(result)
def all_for_use_case(self, use_case: str) -> List[Dict]:
result = super().get_entries(self._collection, projection={'_id': False}, selection={"use_case": use_case})
return list(result)
\ No newline at end of file
# global imports (dont't worry, red is normal)
import network_constants as netconst
from database.MongoRepositoryBase import MongoRepositoryBase
from lib.database.entities.trust_adapter import TrustAdapter
from typing import List, Dict
class TrustAdapterRepository(MongoRepositoryBase):
'''This is a repository for MongoDb.'''
def __init__(self):
super().__init__(netconst.REPUTATION_CALCULATION_DB_HOSTNAME,
netconst.REPUTATION_CALCULATION_DB_PORT,
'reputation-computation-db')
self._collection = 'trust_adapter'
def add(self, adapter: TrustAdapter):
super().insert_entry(self._collection, adapter.to_serializable_dict())
def all(self) -> List[Dict]:
result = super().get_entries(self._collection, projection={'_id': False})
return list(result)
def all_for_use_case_and_context(self, use_case: str, context: str) -> List[Dict]:
result = super().get_entries(
self._collection,
projection={'_id': False},
selection={"use_case": use_case, "context": context}
)
return list(result)
def all_for_use_case_and_table(self, use_case: str, table: str) -> List[Dict]:
result = super().get_entries(
self._collection,
projection={'_id': False},
selection={"use_case": use_case, "table": table}
)
return list(result)
def one_for_use_case_and_context_and_table(self, use_case: str, context: str, table: str) -> Dict:
result = super().get_entries(
self._collection,
projection={'_id': False},
selection={"use_case": use_case, "context": context, "table": table}
)
result = list(result)
if len(result) != 1:
return None
return result[0]
\ No newline at end of file
# global imports (dont't worry, red is normal)
import network_constants as netconst
from database.MongoRepositoryBase import MongoRepositoryBase
from lib.database.entities.trust_trace import TrustTrace
from typing import List, Dict
class TrustTraceRepository(MongoRepositoryBase):
'''This is a repository for MongoDb.'''
def __init__(self):
super().__init__(netconst.REPUTATION_CALCULATION_DB_HOSTNAME,
netconst.REPUTATION_CALCULATION_DB_PORT,
'reputation-computation-db')
self._collection = 'trust_trace'
def add(self, trace: TrustTrace):
super().insert_entry(self._collection, trace.to_serializable_dict())
def all(self) -> List[Dict]:
result = super().get_entries(
self._collection, projection={'_id': False})
return list(result)
def all_for_use_case_and_context(self, use_case: str, context: str) -> List[Dict]:
result = super().get_entries(
self._collection,
projection={'_id': False},
selection={"use_case": use_case, "context": context}
)
return list(result)
# global imports (dont't worry, red is normal)
import network_constants as netconst
from database.MongoRepositoryBase import MongoRepositoryBase
from lib.database.entities.user import User
from lib.database.entities.user_trust import UserTrust
from lib.database.repositories.user_trust_repository import UserTrustRepository
from typing import List, Dict
class UserRepository(MongoRepositoryBase):
'''This is a repository for MongoDb.'''
_user_trust_repository = UserTrustRepository()
def __init__(self):
super().__init__(netconst.REPUTATION_CALCULATION_DB_HOSTNAME,
netconst.REPUTATION_CALCULATION_DB_PORT,
'reputation-computation-db')
self._collection = 'user'
def add(self, user: User):
super().insert_entry(self._collection, user.to_serializable_dict())
def all(self) -> List[User]:
result = super().get_entries(
self._collection, projection={'_id': False})
result = [User.from_serializable_dict(row) for row in list(result)]
for user in result:
self._enrich_user(user)
return result
def all_for_use_case(self, use_case: str) -> List[User]:
result = super().get_entries(self._collection, projection={
'_id': False}, selection={"use_case": use_case})
result = [User.from_serializable_dict(row) for row in list(result)]
for user in result:
self._enrich_user(user)
return result
def one_by_use_case_and_username(self, use_case: str, username: str) -> User:
result = list(super().get_entries(self._collection, projection={
'_id': False}, selection={"use_case": use_case, "name": username}))
if len(result) != 1:
return None
user: User = User.from_serializable_dict(result[0])
self._enrich_user(user)