fix display of results

master
Niko PLP 2 weeks ago
parent d9de913e56
commit 4bd1e2b7de
  1. 6
      ng-app/src/apps/ContactEditor.svelte
  2. 40
      ng-app/src/apps/SocialQueryDemo.svelte
  3. 2
      ng-sdk-js/example-webapp-react-socialquery/package.json
  4. 33
      ng-verifier/src/inbox_processor.rs
  5. 4
      ng-verifier/src/request_processor.rs
  6. 4
      ng-verifier/src/verifier.rs

@ -90,21 +90,21 @@
}
async function test() {
await on_qr_scanned("AgBX7NyrH_8cF47eeqkkFwtHFi-LrjrxOoRLNM0EScA1NAABANpOlaBYozbkSDVJFAUG2nSWSTXXD-wiLRG6ZUU23f8GCWFjY291bnQgNAEObmlrbzRAdHJ1ZS5jb20");
await on_qr_scanned("AgBWW2hNMS_1xjz5Pvscq1QQ5D405EWRjoN70kIuAgNIqwABALRXYVWKYVaz6xqNqncU7D2HyheZKlFepLoJVE-xIbywB25pa28gMTMBD2ZpcmVmb3hAcHJvLmNvbQ");
}
</script>
<div class="flex-col p-5"bind:this={container}>
<h1 class="font-bold text-xl text-blue-700">Contact</h1>
<Button
<!-- <Button
on:click={test}
on:keypress={test}
class="select-none ml-2 mt-2 mb-2 text-white bg-primary-700 hover:bg-primary-700/90 focus:ring-4 focus:ring-primary-500/50 rounded-lg text-base p-2 text-center inline-flex items-center dark:focus:ring-primary-700/55"
>
<QrCode tabindex="-1" class="mr-2 focus:outline-none" />
Test
</Button><br/>
</Button><br/> -->
{#if !has_camera && !has_name}
<Alert class="m-2" color="red" style="word-break: break-word;" >No camera available. You cannot import with QR-code</Alert>

@ -39,20 +39,24 @@
},
};
const ranking_query = `SELECT ?mail (SAMPLE(?n) as?name) (MAX(?rust_) as ?rust) (MAX(?svelte_) as ?svelte) (MAX(?tailwind_) as ?tailwind) (MAX(?rdf_) as ?rdf) (MAX(?yjs_) as ?yjs) (MAX(?automerge_) as ?automerge) (SUM(?total_) as ?total) WHERE {
{SELECT ?mail (SAMPLE(?name) as ?n) ?skill (AVG(?value)+1 AS ?score) WHERE {
?rating <http://www.w3.org/2006/vcard/ns#hasEmail> ?mail.
?rating <http://www.w3.org/2006/vcard/ns#fn> ?name.
?rating <did:ng:x:skills#hasRating> ?hasrating.
?hasrating <did:ng:x:skills#rated> ?value.
?hasrating <did:ng:x:skills#skill> ?skill.
} GROUP BY ?mail ?skill }
const ranking_query = `SELECT ?mail (SAMPLE(?n) as?name) (MAX(?rust_) as ?rust) (MAX(?svelte_) as ?svelte) (MAX(?tailwind_) as ?tailwind)
(MAX(?rdf_) as ?rdf) (MAX(?yjs_) as ?yjs) (MAX(?automerge_) as ?automerge) (SUM(?total_) as ?total)
WHERE {
{ SELECT ?mail (SAMPLE(?name) as ?n) ?skill (AVG(?value)+1 AS ?score)
WHERE {
?rating <http://www.w3.org/2006/vcard/ns#hasEmail> ?mail.
?rating <http://www.w3.org/2006/vcard/ns#fn> ?name.
?rating <did:ng:x:skills#hasRating> ?hasrating.
?hasrating <did:ng:x:skills#rated> ?value.
?hasrating <did:ng:x:skills#skill> ?skill.
} GROUP BY ?mail ?skill
}
BIND (IF(sameTerm(?skill, <did:ng:k:skills:programming:rust>), ?score, 0) AS ?rust_)
BIND (IF(sameTerm(?skill, <did:ng:k:skills:programming:svelte>), ?score, 0) AS ?svelte_)
BIND (IF(sameTerm(?skill, <did:ng:k:skills:programming:tailwind>), ?score, 0) AS ?tailwind_)
BIND (IF(sameTerm(?skill, <did:ng:k:skills:programming:rdf>), ?score, 0) AS ?rdf_)
BIND (IF(sameTerm(?skill, <did:ng:k:skills:programming:yjs>), ?score, 0) AS ?yjs_)
BIND (IF(sameTerm(?skill, <did:ng:k:skills:programming:yjs>), ?score, 0) AS ?automerge_)
BIND (IF(sameTerm(?skill, <did:ng:k:skills:programming:automerge>), ?score, 0) AS ?automerge_)
BIND (?tailwind_+?svelte_+?rust_+?rdf_+?yjs_+?automerge_ AS ?total_)
} GROUP BY ?mail
ORDER BY DESC(?total)`;
@ -65,7 +69,7 @@ ORDER BY DESC(?total)`;
$: if (commits.graph.length > 4) {
sparql_query(ranking_query, false).then((res) => {
console.log(res.results?.bindings);
//console.log(res.results?.bindings);
results = res.results?.bindings;
});
}
@ -121,7 +125,7 @@ WHERE {
"did:ng:a",
request_nuri,
"did:ng:d:c",
2,
0,
);
} catch (e) {
toast_error(display_error(e));
@ -165,13 +169,13 @@ WHERE {
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 border-gray-200">
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{res.mail.value}</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{res.name.value}</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{res.rust.value}</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{res.svelte.value}</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{res.tailwind.value}</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{res.rdf.value}</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{res.yjs.value}</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{res.automerge.value}</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{res.total.value}</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{Math.round(res.rust.value * 10) / 10 }</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{Math.round(res.svelte.value * 10) / 10 }</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{Math.round(res.tailwind.value * 10) / 10 }</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{Math.round(res.rdf.value * 10) / 10 }</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{Math.round(res.yjs.value * 10) / 10 }</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{Math.round(res.automerge.value * 10) / 10 }</td>
<td scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">{Math.round(res.total.value * 10) / 10 }</td>
</tr>
{/each}
</tbody>

@ -4,7 +4,7 @@
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --host",
"build": "tsc --noEmit && vite build",
"lint": "eslint .",
"preview": "vite preview",

@ -251,7 +251,7 @@ impl Verifier {
//TODO: in case of errors here below, mark the forwarder as ng:social_query_error
if sparql.is_none() { return Err(VerifierError::InvalidSocialQuery); }
log_info!("{}",sparql.as_ref().unwrap());
//log_info!("{}",sparql.as_ref().unwrap());
let res = self.sparql_query(&NuriV0::new_entire_user_site(), sparql.unwrap(), None).await?;
@ -269,7 +269,7 @@ impl Verifier {
}
};
log_info!("{:?}",results);
//log_info!("{:?}",results);
// Do we have local results matching the request's query? If yes, we send them back to the forwarder right away
if !results.is_empty() {
@ -303,13 +303,14 @@ impl Verifier {
// getting the contacts to forward to
let sparql = format!("PREFIX ng: <did:ng:x:ng#>
PREFIX vcard: <http://www.w3.org/2006/vcard/ns#>
SELECT ?profile_id ?inbox_id WHERE
{{ ?c ng:c \"social:contact\" .
{{ ?c a vcard:Individual .
OPTIONAL {{ ?c ng:site ?profile_id . ?c ng:site_inbox ?inbox_id }}
OPTIONAL {{ ?c ng:protected ?profile_id . ?c ng:protected_inbox ?inbox_id }}
FILTER ( bound(?profile_id) && NOT EXISTS {{ ?c ng:site <{profile_id_nuri}> }} && NOT EXISTS {{ ?c ng:protected <{profile_id_nuri}> }} )
}}");
log_info!("{sparql}");
//log_info!("{sparql}");
let sols = match self.sparql_query(
&NuriV0::new_entire_user_site(),
sparql, None).await?
@ -319,7 +320,7 @@ impl Verifier {
};
let degree = if req.degree == 0 { 0 } else { req.degree - 1 };
log_info!("new degree {degree}");
//log_info!("new degree {degree}");
let mut found_contact = false;
let forwarder_id = forwarder_nuri.target.repo_id().clone();
@ -353,7 +354,7 @@ impl Verifier {
}
}
// if not found any contact, we stop here
log_info!("found contact {found_contact}");
//log_info!("found contact {found_contact}");
if !found_contact {
self.mark_social_query_forwarder(&forwarder_nuri_string, &forwarder_nuri, "social_query_ended".to_string()).await?;
let post = InboxPost::new_social_query_response_replying_to(
@ -374,9 +375,11 @@ impl Verifier {
return Err(VerifierError::InvalidSocialQuery)
}
// TODO: first we open the response.forwarder_id (because in webapp, it might not be loaded yet)
let forwarder_nuri = NuriV0::new_repo_target_from_id(&response.forwarder_id);
// TODO: first we open the response.forwarder_id (because in webapp, it might not be loaded yet)
//self.open_for_target(&forwarder_nuri.target, false).await?;
let forwarder_nuri_string = NuriV0::repo_id(&response.forwarder_id);
// checking that we do have a running ForwardedSocialQuery, and that it didnt end, otherwise it must be spam.
match self.sparql_query( &forwarder_nuri, format!("ASK {{ <> <did:ng:x:ng#social_query_id> <{}> }} ",
@ -388,17 +391,17 @@ impl Verifier {
&forwarder_nuri,
"PREFIX ng: <did:ng:x:ng#>
SELECT ?from_profile ?from_inbox ?from_forwarder ?ended WHERE
{{ <> ng:social_query_from_profile ?from_profile .
<> ng:social_query_from_inbox ?from_inbox .
<> ng:social_query_forwarder ?from_forwarder .
<> ng:social_query_ended ?ended .
{{ OPTIONAL {{ <> ng:social_query_from_profile ?from_profile . }}
OPTIONAL {{ <> ng:social_query_from_inbox ?from_inbox .}}
OPTIONAL {{ <> ng:social_query_forwarder ?from_forwarder .}}
OPTIONAL {{ <> ng:social_query_ended ?ended . }}
}}".to_string(),
Some(forwarder_nuri_string)).await?
{
QueryResults::Solutions(mut sols) => {
match sols.next() {
None => {
log_info!("at origin");
//log_info!("at origin and not ended");
(None, None, None)
}
Some(Err(e)) => {
@ -442,7 +445,7 @@ impl Verifier {
}}",
NuriV0::inbox(&msg.body.from_inbox.unwrap())
);
log_info!("{spar}");
//log_info!("{spar}");
let token = match self.sparql_query(
&forwarder_nuri,
//<> ng:social_query_id <{}> NuriV0::inbox(&msg.body.from_inbox.unwrap()),
@ -470,7 +473,7 @@ impl Verifier {
}
_ => return Err(VerifierError::SparqlError(NgError::InvalidResponse.to_string())),
};
log_info!("token = {token}");
//log_info!("token = {token}");
let at_origin = forwarded_from_profile.is_none() || forwarded_from_inbox.is_none() || from_forwarder.is_none();

@ -264,7 +264,7 @@ impl Verifier {
}
}
async fn open_for_target(
pub(crate) async fn open_for_target(
&mut self,
target: &NuriTargetV0,
as_publisher: bool,
@ -823,7 +823,7 @@ impl Verifier {
OPTIONAL {{ ?c ng:protected ?profile_id . ?c ng:protected_inbox ?inbox_id }}
FILTER ( bound(?profile_id) {extra_conditions} )
}}");
log_info!("{sparql}");
//log_info!("{sparql}");
let sols = match self.sparql_query(
&NuriV0::new_entire_user_site(),
sparql, None).await?

@ -1644,7 +1644,7 @@ impl Verifier {
pub async fn inbox(&mut self, msg: InboxMsg, from_queue: bool) {
log_info!("RECEIVED INBOX MSG {:?}", msg);
//log_info!("RECEIVED INBOX MSG {:?}", msg);
match self.inboxes.get(&msg.body.to_inbox) {
Some(repo_id) => {
@ -1653,7 +1653,7 @@ impl Verifier {
if let Some(privkey) = &repo.inbox {
match msg.get_content(privkey) {
Ok(content) => {
log_info!("received msg content {:?}", content);
//log_info!("received msg content {:?}", content);
let res = self.process_inbox(msg, content).await;
if let Err(e) = res {
log_err!("Error during process_inbox {e}");

Loading…
Cancel
Save