Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/scripts/migrate watchlist members #64

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ Output/
[Oo]utput/
[Pp]ublish/

src/GrpcCamera/stream-out/*
src/GrpcCamera/stream-out/*
src/scripts/migrate-watchlist-members/images/*
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/scripts/CompareFilesInFolder/bin/Debug/net6.0/CompareFilesInFolder.dll",
"program": "${workspaceFolder}/src/AutoEnrollment/bin/Debug/net6.0/SmartFace.AutoEnrollment.dll",
"args": [],
"cwd": "${workspaceFolder}/src/scripts/CompareFilesInFolder",
"cwd": "${workspaceFolder}/src/AutoEnrollment",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
Expand Down
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/AEOSSyncTool/AEOSSyncTool.csproj",
"${workspaceFolder}/src/AutoEnrollment/AutoEnrollment.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
Expand All @@ -19,7 +19,7 @@
"type": "process",
"args": [
"publish",
"${workspaceFolder}/src/AEOSSyncTool/AEOSSyncTool.csproj",
"${workspaceFolder}/src/AutoEnrollment/AutoEnrollment.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
Expand All @@ -33,7 +33,7 @@
"watch",
"run",
"--project",
"${workspaceFolder}/src/AEOSSyncTool/AEOSSyncTool.csproj"
"${workspaceFolder}/src/AutoEnrollment/AutoEnrollment.csproj"
],
"problemMatcher": "$msCompile"
}
Expand Down
27 changes: 18 additions & 9 deletions src/AEOS/AeosSync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,34 @@
# SF to AeosSync Adapter
This application connects to the SmartFace AccessController gRPC stream, processes `GRANTED` notifications and sends `Open` requests to AeosSync Server

## Development
## Running
To run the application locally, follow these steps
- open terminal
- navigate to /src/AeosSync
- run `dotnet run`

## Deployment
## Deployment
To deploy the application, follow these steps
- open terminal
- navigate to /src/AeosSync
- run `dotnet publish -c Release -r win10-x64 --self-contained true -p:ReadyToRun=false -p:PublishSingleFile=true -p:PublishTrimmed=false -p:IncludeNativeLibrariesForSelfExtract=true -p:IncludeAllContentForSelfExtract=true`



### Deploy to Docker
- navigate to the root of this repo
- run the following commands
- `docker build -f src/AEOS/AeosSync/Dockerfile -t registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.5 .`
- `docker tag registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.5 registry.gitlab.com/innovatrics/smartface/integrations-aeossync:latest`
- `docker push registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.5`
- `docker build -f src/AEOS/AeosSync/Dockerfile -t registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.6 .`
- `docker tag registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.6 registry.gitlab.com/innovatrics/smartface/integrations-aeossync:latest`
- `docker push registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.6`
- `docker push registry.gitlab.com/innovatrics/smartface/integrations-aeossync:latest`

### Deploy to Docker on Arm
- navigate to the root of this repo
- run the following commands
- `docker build -f src/AEOS/AeosSync/arm.Dockerfile -t registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.5-arm .`
- `docker tag registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.5-arm registry.gitlab.com/innovatrics/smartface/integrations-aeossync:latest-arm`
- `docker push registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.5-arm`
- `docker build -f src/AEOS/AeosSync/arm.Dockerfile -t registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.6-arm .`
- `docker tag registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.6-arm registry.gitlab.com/innovatrics/smartface/integrations-aeossync:latest-arm`
- `docker push registry.gitlab.com/innovatrics/smartface/integrations-aeossync:0.6-arm`
- `docker push registry.gitlab.com/innovatrics/smartface/integrations-aeossync:latest-arm`

## Usage
Expand Down Expand Up @@ -57,4 +59,11 @@ networks:
external:
name: sf-network

```
```

## Update references

### SOAP
`dotnet tool install --global dotnet-svcutil`
`dotnet-svcutil --roll-forward LatestMajor https://<aeosServerIp>:8443/aeosws?wsdl`

12 changes: 5 additions & 7 deletions src/AEOS/AeosSync/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"SmartFace": {
"FirstNameOrder": "last",
"RestApi": {
"ServerUrl": "",
"ServerUrl": "http://192.168.17.20:8098",
"PageSize": 100
},
"GraphQL": {
"ServerUrl": "",
"ServerUrl": "http://192.168.17.20:8097/graphql/",
"PageSize": 100
},
"Export": {
Expand All @@ -48,9 +48,9 @@
},
"Aeos": {
"Server": {
"Wsdl": "",
"Wdsl": "https://192.168.1.10:8443/aeosws?wsdl",
"PageSize": 100,
"User": "",
"User": "admin",
"Pass": ""
},
"Integration": {
Expand All @@ -59,13 +59,11 @@
"BiometricEnrollmentStatus": "BiometricEnrollmentStatus",
"SmartFaceKeepUser": "SmartFaceKeepUser",
"DefaultTemplates": {
"7thFloorTemplateClaimablePermanent": true,
"6thFloorTemplateClaimablePermanent": true
}
},
"NoImageWarningNotification":false,
"AutoBiometryEnablement":true,
"AutoBiometryPrefix":"",
"AutoBiometryPrefix":"aeos_",
"KeepPhotoUpToDate":true

}
Expand Down
2 changes: 1 addition & 1 deletion src/MyQConnector/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"AccessController": {
"Schema": "http",
"Host": "10.11.64.67",
"Host": "192.168.1.11",
"Port": 5050
},

Expand Down
140 changes: 140 additions & 0 deletions src/scripts/migrate-watchlist-members/get_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import requests
import os

def rearrange_name(fullname):
# Split the full name into words
name_parts = fullname.split()

# Check if the name has more than one word
if len(name_parts) > 1:
# Move the first word (assumed to be the surname) to the end
rearranged_name = " ".join(name_parts[1:] + [name_parts[0]])
else:
# If there's only one word, return it as is
rearranged_name = fullname

return rearranged_name

def apply_curl_to_items(api_url, image_data_ids, save_to_folder):
print("Downloading images:")
#print(image_data_ids)

for image_id, full_name, display_name in image_data_ids:
url = f"{api_url}/{image_id}"
headers = {"accept": "image/jpeg"}

try:
response = requests.get(url, headers=headers)

# Check if the request was successful (status code 200)
if response.status_code == 200:
# Save the image data to a file in the specified folder
file_name = full_name if full_name else display_name
file_path = os.path.join(save_to_folder, f"{file_name}_{image_id}.jpg")
with open(file_path, "wb") as file:
file.write(response.content)
print(f"Image saved: {file_path}")
else:
print(f"Failed to retrieve image with id: {image_id}, Status code: {response.status_code}")

except requests.exceptions.RequestException as e:
print(f"An error occurred while processing image with id: {image_id}, Error: {e}")


if __name__ == '__main__':
api_url = 'http://192.168.1.11:8098/api/v1/Images' # Replace with the actual API endpoint for image retrieval
save_to_folder = "./images/"

# GraphQL endpoint URL
graphql_url = "http://192.168.1.11:8097/graphql/"

# GraphQL query
query = """
query($skip: Int!, $take: Int!)
{
watchlistMembers(
where: {watchlists: {all: {id: {eq: "innovatrics"}}}},
skip:$skip,
take:$take
) {
items {
displayName
fullName
tracklet {
faces(where: {faceType: {eq: REGULAR}}) {
imageDataId
faceType
}
}
}
totalCount
}
}
"""

take = 100 # Number of items to fetch per request
skip = 0 # Starting point for each batch
has_more_data = True
all_data = []
image_data_ids = [] # Initialize this at a higher scope so it can be used later

# Set up headers for the request
headers = {
"Content-Type": "application/json",
}

image_data_ids = []
while has_more_data:
# Set up the variables for the GraphQL query
variables = {
"skip": skip,
"take": take
}

try:
# Make the GraphQL request with variables
response = requests.post(graphql_url, json={"query": query, "variables": variables}, headers=headers)
response.raise_for_status() # Check for HTTP errors
data = response.json()

if "errors" in data:
print(f"Error: {data['errors']}")
break

# Update skip for the next batch
skip += take

# Extract imageDataId values

totalCount = data["data"]["watchlistMembers"]["totalCount"]
for item in data["data"]["watchlistMembers"]["items"]:
fullname = item["fullName"]
displayname = item["displayName"]
for faces in item["tracklet"]["faces"]:
# Check if watchlistMember is a string or a dictionary
facedata = faces["imageDataId"]

if fullname is None and displayname is not None:
fullname = displayname

fullname = rearrange_name(fullname)

image_data_ids.append((facedata, fullname, displayname))
print(facedata, fullname)

# Check if we've fetched all items
if skip >= totalCount:
has_more_data = False

except requests.exceptions.RequestException as e:
print("An error occurred:", e)
print("Response content:", response.content)
break

#After fetching all the data, call apply_curl_to_items to download images
if image_data_ids:
try:
apply_curl_to_items(api_url, image_data_ids, save_to_folder)
except requests.exceptions.RequestException as e:
print("Error while downloading an image:", e)
print("Response content:", response.content)
Loading