Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wotmap
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tools
wotmap
Commits
4a6e516a
Commit
4a6e516a
authored
Jan 11, 2019
by
Pierre-Jean CHANCELLIER
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace PHP script by Python script o query the new duniter database
parent
adbc9117
Pipeline
#4356
failed with stages
in 32 seconds
Changes
5
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
179 deletions
+20
-179
.gitignore
.gitignore
+0
-1
README.md
README.md
+15
-2
wot.json
data/wot.json
+1
-1
update-data-sigmajs.php
script/update-data-sigmajs.php
+0
-173
wot_json.py
script/wot_json.py
+4
-2
No files found.
.gitignore
View file @
4a6e516a
/img/photos/*.png
.idea/
README.md
View file @
4a6e516a
...
...
@@ -28,7 +28,20 @@ Exploration de la Toile de Confiance de Duniter utilisant la librairie javascrip
*
Possibilité de mettre l'animation en pause pour économiser des ressources processeur
*
Possibilité d'afficher ou de masquer les liens pour économiser des ressources machines lors du calcul de la position des noeuds
## Automatisation de la mise à jour des données (CRON)
## Installation
### Dossier d'installation
Déposez le dossier wotmap et son arborescence dans le dossier HOME de votre utilisateur duniter (par ex : /var/lib/duniter/wotmap)
### Paramétrage d'Apache
Alias /wotmap /var/lib/duniter/wotmap
<Directory
/
var
/
lib
/
duniter
/
wotmap
>
Options FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
### Automatisation de la mise à jour des données (CRON)
Créez le fichier
***/etc/cron.d/wotmap**
*
sur votre serveur pour automatiser le lancement du script :
````30 3 * * *
root php /var/www/wotmap/script/update-data-sigmajs.php
>> /var/log/wotmap/wotmap.log 2>&1````
````30 3 * * *
duniter python3 /var/lib/duniter/wotmap/script/wot_json.py
>> /var/log/wotmap/wotmap.log 2>&1````
data/wot.json
View file @
4a6e516a
This diff is collapsed.
Click to expand it.
script/update-data-sigmajs.php
deleted
100644 → 0
View file @
adbc9117
<?php
$datum
=
date
(
"dmY H:i"
);
$stepmax
=
5
;
// Definit le serveur elasticSearch à interroger
define
(
"URL_ES"
,
"http://g1.data.le-sou.org"
);
// Definit l'emplacement du fichier de base de données
define
(
"PATH"
,
"/var/lib/duniter/.config/duniter/duniter_default/duniter.db"
);
// Definit l'endroit où le fichier de sortie sera enregistré
define
(
"OUTPATH"
,
dirname
(
__FILE__
)
.
"/../data/"
);
// Definit à partir de quelle identité on démarre le parcours de la toile
define
(
"PUBKEY_CGEEK"
,
"2ny7YAdmzReQxAayyJZsyVYwYhVyax2thKcGknmQy5nQ"
);
$tab_final
[
'nodes'
]
=
[];
$tab_final
[
'edges'
]
=
[];
$tab_tmp
=
[
0
=>
[
'label'
=>
'cgeek'
,
'pubkey'
=>
PUBKEY_CGEEK
]
];
try
{
// Connexion à la BDD
$pdo
=
new
PDO
(
'sqlite:'
.
PATH
);
$pdo
->
setAttribute
(
PDO
::
ATTR_DEFAULT_FETCH_MODE
,
PDO
::
FETCH_ASSOC
);
$pdo
->
setAttribute
(
PDO
::
ATTR_ERRMODE
,
PDO
::
ERRMODE_EXCEPTION
);
// ERRMODE_WARNING | ERRMODE_EXCEPTION | ERRMODE_SILENT
}
catch
(
Exception
$e
)
{
echo
$datum
.
" : Impossible d'accéder à la base de données SQLite : "
.
$e
->
getMessage
()
.
PHP_EOL
;
die
();
}
// Permet d'éviter une erreur avec getimagesize si la photo n'existe pas
// mais introduit une fuite mémoire
//function exception_error_handler( $errno, $errstr, $errfile, $errline ) {
// throw new Exception($errstr);
//}
//set_error_handler("exception_error_handler");
$i
=
0
;
while
(
array_key_exists
(
$i
,
$tab_tmp
)){
echo
date
(
"Y-m-d H:i:s"
)
.
', usage mémoire : '
.
round
(
memory_get_usage
()
/
1024
/
1024
)
.
'M / '
.
ini_get
(
'memory_limit'
)
.
" ~ "
.
$i
.
' : '
.
$tab_tmp
[
$i
][
'label'
]
//. " (découverte des voisins et copie locale de l'avatar)"
.
PHP_EOL
;
$img_relative_path
=
'img/photos/'
;
$img_absolute_path
=
realpath
(
dirname
(
__FILE__
)
.
'/../'
.
$img_relative_path
)
.
'/'
;
$img_filename
=
$tab_tmp
[
$i
][
'pubkey'
]
.
'.png'
;
$img_path_json
=
$img_relative_path
.
$img_filename
;
$img_target
=
$img_absolute_path
.
$img_filename
;
$img_url
=
URL_ES
.
'/user/profile/'
.
$tab_tmp
[
$i
][
'pubkey'
]
.
'/_image/avatar.png'
;
if
(
!
file_exists
(
$img_target
)){
if
(
!
copy
(
$img_url
,
$img_target
))
$img_path_json
=
'img/logo-g1.png'
;
}
elseif
((
time
()
-
filemtime
(
$img_target
))
>
604800
){
unlink
(
$img_target
);
copy
(
$img_url
,
$img_target
);
}
$objmember
=
[
'id'
=>
strval
(
$i
+
1
),
'label'
=>
$tab_tmp
[
$i
][
'label'
],
'type'
=>
'image'
,
'url'
=>
$img_path_json
,
'x'
=>
0.0
,
'y'
=>
0.0
,
'size'
=>
0
,
'color'
=>
'rgba(255,0,0,1)'
,
'attributes'
=>
[
'pubkey'
=>
$tab_tmp
[
$i
][
'pubkey'
],
'degree'
=>
0
,
'referent'
=>
false
]
];
$voisins
=
recuperer_voisins
(
$objmember
);
$objmember
[
'size'
]
=
count
(
$voisins
);
$objmember
[
'attributes'
][
'degree'
]
=
$objmember
[
'size'
];
$tab_final
[
'nodes'
][]
=
$objmember
;
$i
++
;
}
// Déconnexion à la BDD
$pdo
=
null
;
// Détermination du statut de référent
$nb_nodes
=
count
(
$tab_final
[
'nodes'
]);
$crit_referent
=
ceil
(
pow
(
$nb_nodes
,
1
/
$stepmax
));
foreach
(
$tab_final
[
'nodes'
]
as
$key
=>
$value
)
{
$isreferent
=
(
$tab_final
[
'nodes'
][
$key
][
'attributes'
][
'inDegree'
]
>=
$crit_referent
)
&&
(
$tab_final
[
'nodes'
][
$key
][
'attributes'
][
'outDegree'
]
>=
$crit_referent
);
$tab_final
[
'nodes'
][
$key
][
'attributes'
][
'referent'
]
=
$isreferent
;
if
(
$isreferent
){
$tab_final
[
'nodes'
][
$key
][
'color'
]
=
'rgba(0,128,0,1)'
;}
}
// Ecriture du résultat dans un fichier
$json
=
json_encode
(
$tab_final
,
JSON_UNESCAPED_SLASHES
);
try
{
$file
=
fopen
(
OUTPATH
.
'wot.json'
,
'w+'
);
fwrite
(
$file
,
$json
);
fclose
(
$file
);
echo
$datum
.
" : recuperation des donnees de la wotmap terminee"
.
PHP_EOL
;
}
catch
(
Exception
$e
){
echo
$datum
.
" : Impossible d'enregistrer le fichier de sortie : "
.
$e
->
getMessage
()
.
PHP_EOL
;
die
();
}
/* ======================================
== Fonctions personnalisees ==
====================================== */
function
recuperer_voisins
(
&
$member
){
global
$tab_final
;
global
$pdo
;
$voisins
=
[];
// On récupère les certifs emises par le membre
$stmt
=
$pdo
->
prepare
(
"SELECT * FROM c_index AS c, i_index AS i WHERE c.receiver = i.pub AND c.issuer = :pubkey"
);
$stmt
->
execute
(
array
(
'pubkey'
=>
$member
[
'attributes'
][
'pubkey'
]));
$certifs_donnees
=
$stmt
->
fetchAll
();
$member
[
'attributes'
][
'outDegree'
]
=
count
(
$certifs_donnees
);
foreach
(
$certifs_donnees
as
$certif
){
$voisin
=
[
'label'
=>
$certif
[
'uid'
],
'pubkey'
=>
$certif
[
'pub'
]];
$voisins
[]
=
$voisin
;
$edge
=
[
'id'
=>
strval
(
count
(
$tab_final
[
'edges'
])
+
1
),
'source'
=>
$member
[
'id'
],
'target'
=>
strval
(
idvoisin
(
$voisin
))];
$tab_final
[
'edges'
][]
=
$edge
;
}
// On récupère les certifs recues par le membre
$stmt
=
$pdo
->
prepare
(
"SELECT * FROM c_index AS c, i_index AS i WHERE c.issuer = i.pub AND c.receiver = :pubkey"
);
$stmt
->
execute
(
array
(
'pubkey'
=>
$member
[
'attributes'
][
'pubkey'
]));
$certifs_recues
=
$stmt
->
fetchAll
();
$member
[
'attributes'
][
'inDegree'
]
=
count
(
$certifs_recues
);
foreach
(
$certifs_recues
as
$certif
){
$voisin
=
[
'label'
=>
$certif
[
'uid'
],
'pubkey'
=>
$certif
[
'pub'
]];
if
(
!
in_array
(
$voisin
,
$voisins
)){
$voisins
[]
=
$voisin
;
idvoisin
(
$voisin
);
}
}
// Retourne la liste des voisins uniques du membre
return
$voisins
;
}
function
idvoisin
(
$tabvoisin
){
global
$tab_tmp
;
$key
=
recursive_array_search
(
$tabvoisin
[
'pubkey'
],
$tab_tmp
);
if
(
!
is_numeric
(
$key
)){
$return
=
array_push
(
$tab_tmp
,
$tabvoisin
);
}
else
{
$return
=
$key
+
1
;
}
// Retourne l'id du voisin dans le tableau $tab_tmp
return
$return
;
}
/* Fonction récupérée dans la doc de PHP pour chercher récursivement une valeur dans un tableau multidimensionnel */
function
recursive_array_search
(
$needle
,
$haystack
)
{
foreach
(
$haystack
as
$key
=>
$value
)
{
$current_key
=
$key
;
if
(
$needle
===
$value
OR
(
is_array
(
$value
)
&&
recursive_array_search
(
$needle
,
$value
)
!==
false
))
{
return
$current_key
;
}
}
return
false
;
}
?>
\ No newline at end of file
script/wot_json.py
View file @
4a6e516a
...
...
@@ -38,7 +38,7 @@ if __name__ == "__main__":
Default options:
-i ~/.config/duniter/duniter_default/data/leveldb
-o wot.json
-o
~/wotmap/data/
wot.json
-e http://g1.data.le-sou.org
-a ../img/photos
-A img/photos
...
...
@@ -47,12 +47,13 @@ Default options:
exit
()
# Initialize
os
.
system
(
'duniter stop'
)
outdata
=
{
"nodes"
:[],
"edges"
:[]}
index
=
{}
# pub -> id
# Read args
dbpath
=
os
.
path
.
expanduser
(
getargv
(
"-i"
,
"~/.config/duniter/duniter_default/data/leveldb"
))
outpath
=
os
.
path
.
expanduser
(
getargv
(
"-o"
,
"wot.json"
))
outpath
=
os
.
path
.
expanduser
(
getargv
(
"-o"
,
"
~/wotmap/data/
wot.json"
))
url_es
=
getargv
(
"-e"
,
"http://g1.data.le-sou.org"
)
download_avatars
=
"-d"
in
sys
.
argv
avatars_path
=
os
.
path
.
expanduser
(
getargv
(
"-a"
,
"../img/photos"
))
...
...
@@ -157,3 +158,4 @@ Default options:
outfile
=
open
(
outpath
,
"w"
)
json
.
dump
(
outdata
,
outfile
)
outfile
.
close
()
os
.
system
(
'duniter start'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment