Skip to content
Extraits de code Groupes Projets
Valider f249f51e rédigé par Thomas MESLIN's avatar Thomas MESLIN
Parcourir les fichiers

Add fold and parser optimization done

parent 0213fca8
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -298,7 +298,25 @@ let iter rand_csv col_name f =
List.iter
(fun a -> f a.(idx))
rand_csv.data
(*
fold une colonne a partir de la fonction f
fold : csv -> string -> ('a -> string -> 'a) -> 'a -> 'a
Ex :
let moncsv =
col1, col2, col3, col4
a0 , b0 , c0 , d0
a1 , b1 , c1 , d1
a2 , b2 , c2 , d2
a3 , b3 , c3 , d3
fold moncsv "col1" (fun x elt -> x+1) 0 =
4
*)
let fold rand_csv col_name f depart =
let idx = trouve_indice rand_csv.column_name col_name in
List.fold_left (fun acc elt -> f acc (elt.(idx))) depart rand_csv.data
(*
Sauvegarde le csv au chemin file_name au format csv. (,) comme séparateur
......
......@@ -5,6 +5,13 @@ let create_gexf path node_data edge_data =
let t = Unix.time () in
let tm = Unix.localtime t in
let date = Printf.sprintf "%4d-%02d-%02d" (tm.tm_year+1900) (tm.tm_mon+1) tm.tm_mday in (*yyyy-mm-dd*)
let node_col0 = Csv.get_column node_data |> List.hd in
let n_node = Csv.fold node_data node_col0 (fun x _ -> x+1) 0 in
let edge_col0 = Csv.get_column edge_data |> List.hd in
let n_edge = Csv.fold edge_data edge_col0 (fun x _ -> x+1) 0 in
(*Création de l'HEADER*)
output_string oc "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
output_string oc
......@@ -19,17 +26,18 @@ let create_gexf path node_data edge_data =
</meta>\n");
(*End_HEADER*)
(*Start graph*)
output_string oc " <graph defaultedgetype=\"undirected\">\n";
output_string oc " <graph defaultedgetype=\"undirected\" idtype=\"integer\">\n";
(*Ajout de la categorie*)
output_string oc
" <attributes class=\"node\">
<attribute id=\"0\" title=\"cat\" type=\"string\">
<default>Eleve</default>
<options>[Eleve,Asso]</options>
</attribute>
</attributes>\n";
(*start nodes*)
output_string oc " <nodes>\n";
output_string oc (Printf.sprintf " <nodes count=\"%d\">\n" n_node);
Csv.iter_line node_data
(fun htab ->
......@@ -56,7 +64,7 @@ let create_gexf path node_data edge_data =
(*end nodes*)
output_string oc " </nodes>\n";
(*start edges*)
output_string oc " <edges>\n";
output_string oc (Printf.sprintf " <edges count=\"%d\">\n" n_edge);
Csv.iter_line edge_data
(fun htab ->
......@@ -89,19 +97,21 @@ let () = begin
let edge_data = Csv.open_as_csv "../../res_script/edges_avec_fantome.csv" in
(*Source,Target,Type,Id,Weight*)
create_gexf "../../res_script/graphe_assos_actif_frantome.gexf" node_data edge_data;
print_endline "Graphe assos actif frantome crée.";
let node_data = Csv.open_as_csv "../../res_script/nodes_sans_fantome.csv" in
(*Id,Label,Categorie*)
let edge_data = Csv.open_as_csv "../../res_script/edges_sans_fantome.csv" in
(*Source,Target,Type,Id,Weight*)
create_gexf "../../res_script/graphe_assos_actif.gexf" node_data edge_data;
print_endline "Graphe assos actif crée";
let node_data = Csv.open_as_csv "../../res_script/nodes_eleve_vs_fantome.csv" in
(*Id,Label,Categorie*)
let edge_data = Csv.open_as_csv "../../res_script/edges_eleve_vs_fantome.csv" in
(*Source,Target,Type,Id,Weight*)
create_gexf "../../res_script/graphe_eleve_vs_fantome.gexf" node_data edge_data;
print_endline "Graphe actif vs fantom";
print_endline "Graphes exporté au bon format avec succès"
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter