Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 3b0a966e authored by Antoine Blanquet's avatar Antoine Blanquet
Browse files

Merging with devices implementation, work to do : testing with momentJS !

parents a6fc7149 f1e0132a
#!/bin/bash
# Parameters
if [[ $# -ne 2 ]] ; then
echo "Usage: $0 DID OID"
exit 1
fi
DID="$1/devices"
OID="$2"
tmp=$(grep $DID < .devices.html)
replacement=${tmp/"null"/"$OID"}
if [ -z "$replacement" ]
then
exit
else
sed -i "/${DID//\//\\/}/c $replacement" .devices.html
fi
\ No newline at end of file
{
"totalCount": "21",
"result": [
{
"id": "e24f43fffe44d05f",
"lastState": "passive"
},
{
"id": "e24f43fffe44cf7c",
"lastState": "active"
},
{
"id": "70b3d58ff1012b89",
"lastState": "active"
},
{
"id": "e24f43fffe44d1ca",
"lastState": "passive"
},
{
"id": "a81758fffe032273",
"lastState": "active"
},
{
"id": "0004a30b00241873",
"lastState": "passive"
},
{
"id": "0004a30b001ff623",
"lastState": "passive"
},
{
"id": "1111111111111111",
"lastState": "passive"
},
{
"id": "0025ca0a000004d2",
"lastState": "active"
},
{
"id": "244e7b0002000814",
"lastState": "active"
},
{
"id": "0004a30b00237b0c",
"lastState": "passive"
},
{
"id": "e24f43fffe44d342",
"lastState": "passive"
},
{
"id": "e24f43fffe44d333",
"lastState": "active"
},
{
"id": "e24f43fffe44d13a",
"lastState": "passive"
},
{
"id": "e24f43fffe44cf48",
"lastState": "passive"
},
{
"id": "0025ca0a000004db",
"lastState": "active"
},
{
"id": "e24f43fffe44c2c8",
"lastState": "passive"
},
{
"id": "70b3d58ff1004297",
"lastState": "active"
},
{
"id": "e24f43fffe44cff3",
"lastState": "passive"
},
{
"id": "e24f43fffe44c2cb",
"lastState": "passive"
},
{
"id": "e24f43fffe44cf96",
"lastState": "passive"
}
]
}
{
"totalCount": "22",
"result": [
{
"id": "0000024b0805031a",
"lastState": "active"
},
{
"id": "7276ff0039030716",
"lastState": "active"
},
{
"id": "7276ff0039030724",
"lastState": "active"
},
{
"id": "7276ff0039030871",
"lastState": "active"
},
{
"id": "0080e1ffff0153f1",
"lastState": "passive"
},
{
"id": "0080e1ffff011234",
"lastState": "passive"
},
{
"id": "0080e1ffff0153d7",
"lastState": "passive"
},
{
"id": "080027ffff052e4a",
"lastState": "passive"
},
{
"id": "0080e1ffff014fe1",
"lastState": "passive"
},
{
"id": "0080e1ffff014feb",
"lastState": "passive"
},
{
"id": "0080e1ffff01523c",
"lastState": "passive"
},
{
"id": "0080e1ffff01523e",
"lastState": "passive"
},
{
"id": "0080e1ffff015240",
"lastState": "passive"
},
{
"id": "0080e1ffff015241",
"lastState": "passive"
},
{
"id": "0080e1ffff015242",
"lastState": "passive"
},
{
"id": "0080e1ffff015244",
"lastState": "passive"
},
{
"id": "0080e1ffff015252",
"lastState": "passive"
},
{
"id": "0080e1ffff015253",
"lastState": "passive"
},
{
"id": "0080e1ffff015256",
"lastState": "passive"
},
{
"id": "0080e1ffff015257",
"lastState": "passive"
},
{
"id": "0080e1ffff01525e",
"lastState": "passive"
},
{
"id": "0080e1ffff015abf",
"lastState": "passive"
}
]
}
.result | sort_by(.lastSeenAt, .devEUI) | reverse [] | ("<li><a href='" + @uri "https://lns.campusiot.imag.fr/#/organizations/\(.organizationID)/applications/\(.applicationID)/devices/\(.devEUI)" + "'>" + .devEUI + "</a>: " + .name + " (profile " + .deviceProfileName + " ,org " + .organizationID + ") - " + .lastSeenAt + "</li>" )
.result | sort_by(.lastSeenAt, .devEUI) | reverse [] | select(.!=null) | ("<li><a href='" + @uri "https://lns.campusiot.imag.fr/#/organizations/\(.organizationID)/applications/\(.applicationID)/devices/\(.devEUI)" + "'>" + .devEUI + "</a>: " + .name + " (profile " + .deviceProfileName + " ,org " + .organizationID + ") - " + .lastSeenAt + "</li>" )
......@@ -64,12 +64,18 @@ HEAD="${CURL} -X HEAD --header \""$ACCEPT_JSON"\""
ids_org=$(jq --raw-output ".result[] | .id" ${DATA_ORG_FOLDER}.organizations.json)
ids_org_array=($ids_org)
nb_devices=0
DID=() #List of Devices' IDs
OID=() #List of Organisations' IDs linked to the DID (ex OID[0] is the orgID of DID[0])
for ((i=0; i<${#ids_org_array[@]}; i++))
do
ids_app=$(jq --raw-output ".result[] | .id" ${DATA_APP_FOLDER}.organization${ids_org_array[i]}_applications.json)
ids_app_array=($ids_app)
for ((j=0; j<${#ids_app_array[@]}; j++))
do
DID[$nb_devices]=${ids_app_array[$j]}
OID[$nb_devices]=${ids_org_array[$i]}
nb_devices=$((nb_devices+1))
${GET} \
--header "$AUTH" ${URL}'/api/devices?limit=9999&applicationID='${ids_app_array[j]} \
> ${DATA_DEV_FOLDER}.application${ids_app_array[j]}_devices.json
......@@ -78,6 +84,14 @@ done
jq -s '.[0].result = [.[].result | add] | .[0]' ${DATA_DEV_FOLDER}.application*.json > ${DATA_DEV_FOLDER}.devices.json
ids=$(jq --raw-output ".result[] | select(.!=null) | .devEUI" ${DATA_DEV_FOLDER}.devices.json)
id=($ids)
tmp=$(grep "totalCount" < ${DATA_DEV_FOLDER}.devices.json)
replacement=${tmp/"1"/"${#id[@]}"}
sed -i "/"totalCount"/c $replacement" ${DATA_DEV_FOLDER}.devices.json
#${GET} \
# --header "$AUTH" ${URL}'/api/devices?limit=9999&offset=0' \
# > .devices.json
......@@ -102,3 +116,11 @@ echo '<h2>Passive devices</h2>' >> .devices.html
jq --raw-output -f devices_to_html.jq ${DATA_DEV_FOLDER}.devices.json | grep -v $TODAY >> .devices.html
echo '</body></html>' >> .devices.html
# ./get_id_devicesChange.sh
for ((i=0; i<${#DID[@]}; i++))
do
./change_url_orgaID.sh ${DID[$i]} ${OID[$i]}
done
#!/bin/bash
TODAY="$(date +"%Y-%m-%d")"
# DATA REPOSITORY
DATA_DEV_FOLDER="data/devices/"
#On stock les ids des devices d'aujourd'hui
ids=$(jq --raw-output ".result[] | select(.!=null) | .devEUI" ${DATA_DEV_FOLDER}.devices.json)
id=($ids)
#On stock les dates de dernière activité des devices d'aujourd'hui
dates=$(jq --raw-output ".result[] | select(.!=null) | .lastSeenAt" ${DATA_DEV_FOLDER}.devices.json)
date=()
date=($dates)
state=()
full_date=()
d=()
for (( i=0; i<${#date[@]}; i++ ))
do
if [[ ${date[$i]} == "null" ]]
then
full_date[$i]=${date[$i]}
d[$i]=${full_date[$i]}
else
full_date[$i]=$(echo ${date[$i]} | tr "T" "\n")
for arg in ${full_date[$i]}
do
d[$i]=$arg
break
done
fi
done
#On stock les states des devices d'aujourd'hui dans un tableau en regardant la date
#de dernière activité des devices
for (( i=0; i<${#d[@]}; i++ ))
do
if [[ "${d[$i]}" == "$TODAY" ]]
then
state[$i]="active"
else
state[$i]="passive"
fi
done
#On stock les ids des devices d'hier
ids_2=$(jq --raw-output ".result[] | .id" ${DATA_DEV_FOLDER}lastdevicesStates.json)
id_2=()
i=0
for ID in $ids_2
do
id_2[$i]=$ID
i=$((i+1))
done
#On stock les states des devices d'hier
full_state=$(jq --raw-output ".result[] | .lastState" ${DATA_DEV_FOLDER}lastdevicesStates.json)
states_2=()
j=0
for s in $full_state
do
state_2[$j]=$s
j=$((j+1))
done
#On compare les states des devices d'aujourd'hui et hier
for (( i=0; i<${#id[@]}; i++ ))
do
for (( j=0; j<${#id_2[@]}; j++ ))
do
if [[ "$id[$i]" == "$id_2[$j]" ]]
then
if [[ "${state[$i]}" != "${state_2[$j]}" ]]
then
if [[ "${state[$i]}" == "active" ]]
then
tmp=$(grep ${id[$i]} < .devices.html)
replacement=${tmp/"<li>"/"<li style="color:green">"}
else
tmp=$(grep ${id[$i]} < .devices.html)
replacement=${tmp/"<li>"/"<li style="color:red">"}
fi
sed -i "/${id[$i]}/c $replacement" .devices.html
fi
fi
done
if [[ ${date[$i]} != "null" ]]
then
tmp=$(grep ${id[$i]} < .devices.html)
dateFromNow=$(node changeDateMomentjs.js ${date[$i]})
replacement=${tmp/${date[$i]}/"$dateFromNow"}
sed -i "/${id[$i]}/c $replacement" .devices.html
fi
done
#On met à jour les states des devices pour le prochain jour
echo "{
\"totalCount\": \"${#id[@]}\",
\"result\": [" > ${DATA_DEV_FOLDER}lastdevicesStates.json
for (( i=0; i<$((${#id[@]}-1)); i++ ))
do
echo " {
\"id\": \"${id[$i]}\",
\"lastState\": \"${state[$i]}\"
}," >> ${DATA_DEV_FOLDER}lastdevicesStates.json
done
echo " {
\"id\": \"${id[$((${#id[@]}-1))]}\",
\"lastState\": \"${state[$((${#id[@]}-1))]}\"
}
]
}" >> ${DATA_DEV_FOLDER}lastdevicesStates.json
\ No newline at end of file
#!/bin/bash
#TODAY="2021-03-02"
TODAY="$(date +"%Y-%m-%d")"
# DATA REPOSITORY
DATA_GAT_FOLDER="data/gateways/"
#We store gateways' ids of the present day
ids=$(jq --raw-output ".result[] | .id" .gateways.json)
id=()
i=0
for ID in $ids
do
id[$i]=$ID
i=$((i+1))
done
ids=$(jq --raw-output ".result[] | .id" ${DATA_GAT_FOLDER}.gateways.json)
id=($ids)
#We store dates from the last activity of the gateways from today
dates=$(jq --raw-output ".result[] | .lastSeenAt" .gateways.json)
dates=$(jq --raw-output ".result[] | .lastSeenAt" ${DATA_GAT_FOLDER}.gateways.json)
date=()
date=($dates)
state=()
......@@ -27,8 +24,8 @@ do
full_date[$i]=${date[$i]}
d[$i]=${full_date[$i]}
else
full_date[$i]=$(echo $date[$i] | tr "T" "\n")
for arg in $full_date[$i]
full_date[$i]=$(echo ${date[$i]} | tr "T" "\n")
for arg in ${full_date[$i]}
do
d[$i]=$arg
break
......@@ -49,7 +46,7 @@ do
done
#We store yesterday gateways ids
ids_2=$(jq --raw-output ".result[] | .id" lastGatewaysStates.json)
ids_2=$(jq --raw-output ".result[] | .id" ${DATA_GAT_FOLDER}lastGatewaysStates.json)
id_2=()
i=0
for ID in $ids_2
......@@ -59,7 +56,7 @@ do
done
#We store yesterday gateways states
full_state=$(jq --raw-output ".result[] | .lastState" lastGatewaysStates.json)
full_state=$(jq --raw-output ".result[] | .lastState" ${DATA_GAT_FOLDER}lastGatewaysStates.json)
states_2=()
j=0
for s in $full_state
......@@ -102,14 +99,14 @@ done
#We update gateways state for the next day
echo "{
\"totalCount\": \"${#id[@]}\",
\"result\": [" > lastGatewaysStates.json
\"result\": [" > ${DATA_GAT_FOLDER}lastGatewaysStates.json
for (( i=0; i<$((${#id[@]}-1)); i++ ))
do
echo " {
\"id\": \"${id[$i]}\",
\"lastState\": \"${state[$i]}\"
}," >> lastGatewaysStates.json
}," >> ${DATA_GAT_FOLDER}lastGatewaysStates.json
done
echo " {
......@@ -117,4 +114,4 @@ echo " {
\"lastState\": \"${state[$((${#id[@]}-1))]}\"
}
]
}" >> lastGatewaysStates.json
\ No newline at end of file
}" >> ${DATA_GAT_FOLDER}lastGatewaysStates.json
\ No newline at end of file
{
"totalCount": "0",
"result": [
{
"id": "",
"lastState": ""
}
]
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment