Skip to content

Commit

Permalink
adds bunches and things
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Sep 2, 2024
1 parent 64a5189 commit 331846e
Show file tree
Hide file tree
Showing 10 changed files with 336 additions and 108 deletions.
2 changes: 1 addition & 1 deletion dnas/ziptest/workdir/dna.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ coordinator:
- name: ziptest
bundled: ../../../target/wasm32-unknown-unknown/release/ziptest.wasm
dependencies:
- name: profiles_integrity
- name: ziptest_integrity
- name: profiles
bundled: ../../../target/wasm32-unknown-unknown/release/profiles.wasm
dependencies:
Expand Down
1 change: 1 addition & 0 deletions dnas/ziptest/zomes/coordinator/ziptest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod thing;
pub mod utils;
use ziptest_integrity::*;

use hdk::prelude::*;
Expand Down
58 changes: 44 additions & 14 deletions dnas/ziptest/zomes/coordinator/ziptest/src/thing.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
use hdk::prelude::*;
use ziptest_integrity::*;
use crate::utils::*;

#[derive(Serialize, Deserialize, Debug)]
pub struct CreateThingInput {
pub thing: Thing,
pub bunch: String,
pub reps: Option<u32>,
pub tag: Option<String>,
}

#[hdk_extern]
pub fn create_thing(thing: Thing) -> ExternResult<Record> {
let thing_hash = create_entry(&EntryTypes::Thing(thing.clone()))?;
let record = get(thing_hash.clone(), GetOptions::default())?
.ok_or(
wasm_error!(
WasmErrorInner::Guest(String::from("Could not find the newly created Thing"))
),
)?;
let path = Path::from("all_things");
create_link(path.path_entry_hash()?, thing_hash.clone(), LinkTypes::AllThings, ())?;
Ok(record)
pub fn create_thing(input: CreateThingInput) -> ExternResult<Vec<Record>> {
let mut i = 0;
let mut results = Vec::new();
let mut reps = 1;
if let Some(r) = input.reps {
reps = r;
}
while i<reps {
let content = if input.reps.is_some() {
format!("{}:{}",i,input.thing.content)
} else {
input.thing.content.clone()
};

let thing = Thing {content};
let thing_hash = create_entry(&EntryTypes::Thing(thing))?;
let record = get(thing_hash.clone(), GetOptions::default())?
.ok_or(
wasm_error!(
WasmErrorInner::Guest(String::from("Could not find the newly created Thing"))
),
)?;
let path = Path::from(input.bunch.clone());
let tag = match input.tag.clone() {
Some(str) => LinkTag::from(str),
None => LinkTag::from(())
};
create_link_relaxed(path.path_entry_hash()?, thing_hash.clone(), LinkTypes::AllThings, tag)?;
results.push(record);
i+=1;
}
Ok(results)
}

#[hdk_extern]
pub fn get_thing(original_thing_hash: ActionHash) -> ExternResult<Option<Record>> {
let input = GetLinksInputBuilder::try_new(original_thing_hash.clone(), LinkTypes::ThingUpdates)?.build();
Expand Down Expand Up @@ -60,10 +91,9 @@ pub fn delete_thing(original_thing_hash: ActionHash) -> ExternResult<ActionHash>
}

#[hdk_extern]
pub fn get_things(_: ()) -> ExternResult<Vec<Link>> {
let path = Path::from("all_things");
pub fn get_things(bunch: String) -> ExternResult<Vec<Link>> {
let path = Path::from(bunch.clone());
let input = GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::AllThings)?.build();
let links = get_links(input)?;

Ok(links)
}
27 changes: 27 additions & 0 deletions dnas/ziptest/zomes/coordinator/ziptest/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use hdk::prelude::*;

pub fn create_link_relaxed<T, E>(
base_address: impl Into<AnyLinkableHash>,
target_address: impl Into<AnyLinkableHash>,
link_type: T,
tag: impl Into<LinkTag>
) -> ExternResult<ActionHash>
where
ScopedLinkType: TryFrom<T, Error = E>,
WasmError: From<E>,
{
let ScopedLinkType {
zome_index,
zome_type: link_type,
} = link_type.try_into()?;
HDK.with(|h| {
h.borrow().create_link(CreateLinkInput::new(
base_address.into(),
target_address.into(),
zome_index,
link_type,
tag.into(),
ChainTopOrdering::Relaxed,
))
})
}
115 changes: 115 additions & 0 deletions ui/src/Bunch.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<script lang="ts">
import { createEventDispatcher, getContext, onDestroy, onMount } from "svelte";
import type { ZipTestStore } from "./store";
import type { EntryHash } from "@holochain/client";
import "@shoelace-style/shoelace/dist/components/skeleton/skeleton.js";
const dispatch = createEventDispatcher();
const { getStore }: any = getContext("store");
let store: ZipTestStore = getStore();
export let bunchHash: EntryHash;
export let bunch: string;
type Moment = {
count: number,
date: Date,
}
let bunchRecord
let bunchContent
const GRAPH_HEIGHT = 200
let start
let unit = 10
let expected = 0
let moments = []
let allFound = false
let seconds = 0
let interval
onMount(async ()=>{
bunchRecord = await store.client.getThing(bunchHash)
bunchContent = JSON.parse(bunchRecord.entry.content)
start = new Date
expected = bunchContent.count*bunchContent.reps
unit = GRAPH_HEIGHT/expected
interval = setInterval(async () => {
const things = await store.client.getThings(bunch)
const count = things.length
moments.push(count)
moments = moments
if (expected == count) {
allFound=true
clearInterval(interval)
interval = undefined
}
seconds +=1
}, 1000);
})
onDestroy(()=>{
if (interval) {
clearInterval(interval)
}
})
</script>

<div class="wrapper">
{#if bunchRecord}
<div class="bunch-content">
{#if allFound}
All {expected} things found after {seconds} seconds.
{:else}
Seconds elapsed: : {seconds}
{/if}
<div>
Start: {start}
</div>
<div class="graph">
<div class="units" style={`height:${GRAPH_HEIGHT+40}px`}><span>{expected}</span></div>
{#each moments as moment,i}
<div style="display:flex;flex-direction:column;align-items:center">
<span style="font-size:80%;padding-left:3px;padding-right:3px">{moment}</span>
<div title={moment} class="bar" style={`height:${moment*unit}px;width:5px`}></div>
<span style="font-size:80%;padding-left:3px;padding-right:3px">{i}</span>

</div>
{/each}
<div class="units" style={`height:${GRAPH_HEIGHT+40}px`}><span>{expected}</span></div>
</div>
</div>
{:else}
<sl-skeleton effect="pulse" style="height: 10px; width: 100%"></sl-skeleton>
{/if}
</div>

<style>
.graph{
display: flex;
align-items: end;
}
.bar {
background-color: red;
justify-content: flex-end;
}
.units {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: right;
}
.wrapper {
padding-left: 10px;
width: 100%;
border-radius: 50%;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.bunch-content {
font-size: 16px;
font-weight: bold;
margin-right: 10px;
}
</style>
1 change: 1 addition & 0 deletions ui/src/Controller.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
}
.test-type {
padding: 5px;
border: solid 1px darkgray;
cursor: pointer;
}
.test-type:hover, .selected {
Expand Down
1 change: 0 additions & 1 deletion ui/src/ControllerStream.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import type { WeaveClient } from "@lightningrodlabs/we-applet";
import StreamPane from "./StreamPane.svelte";
import type { EntryRecord } from "@holochain-open-dev/utils";
import { mdiAlertPlusOutline } from "@mdi/js";
export let roleName = "";
export let client: AppClient;
Expand Down
Loading

0 comments on commit 331846e

Please sign in to comment.