Skip to content

Commit

Permalink
parse also euclid
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Werner committed Oct 29, 2023
1 parent 95bd4c9 commit 2696c93
Show file tree
Hide file tree
Showing 13 changed files with 1,536 additions and 106 deletions.
4 changes: 3 additions & 1 deletion integrator/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
text = (line / other_line)*
line = ws? number ws? content ws?
other_line = ~"[^\\n]*" ws?
number = ~"[0-9.]+"
number = ~"[0-9\\.]+\\-[^:]+\\:" / ~"[0-9][0-9\\.]+"
content = ~"(?:(?!\\d+\\s*\\.).)*" # Match any character until another numbered line or end of text
ws = ~"\\s+"
"""
Expand Down Expand Up @@ -79,3 +79,5 @@ def get_inputs(filename):

parsed_data = parse_text(text)
pprint(parsed_data)

pprint(get_inputs("texts/euclid.txt"))
14 changes: 13 additions & 1 deletion integrator/server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gc
import re
import time

import requests
Expand Down Expand Up @@ -79,7 +80,7 @@ def subfunction(*args, **kwargs):
@socket_event("update_state", "set_task_id")
def handle_update(hash_id):
if not hash_id:
print (f"handle_update hash id null!!! {hash_id=}")
print(f"handle_update hash id null!!! {hash_id=}")
return
gc.collect()

Expand Down Expand Up @@ -109,6 +110,17 @@ def handle_set_user_mods():
return states.get_all()


@socket_event("delete_mod", "refresh")
def handle_delete_mod(hash):
if not hash:
print(f"handle_delete_mod hash id null!!! {hash=}")
return
assert re.match(r"[a-f0-9]{64}", hash)
print(f"delete_mod", hash)
del states[hash]
return hash


@socket_event("set_init_state", "set_state")
def handle_set_state(hash_id):
print(f"handle_set_state {hash_id}")
Expand Down
12 changes: 12 additions & 0 deletions integrator/states.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pickle
from shutil import rmtree

from integrator.reader import parse_text
from integrator.tree import Tree
Expand Down Expand Up @@ -81,5 +82,16 @@ def __setitem__(self, hash_id, state):
tree.save_state(i, hash_id)
print(f"saved {i=} {hash_id} {tree=} ")

def __delitem__(self, key):
rmtree(self.path(key), ignore_errors=True)
try:
os.unlink(self.path(key + "-text"))
except FileNotFoundError:
pass
try:
os.unlink(self.path(key + "-meta"))
except FileNotFoundError:
pass


states = States()
Binary file not shown.
1,372 changes: 1,372 additions & 0 deletions integrator/texts/euclid.txt

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions integrator/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,18 @@ def max_score_triangle_subgraph(G, return_start_node=False):
_G = G.copy()

G = Tree.graph_without_text_sequence(G)

try:
depth = math.log(len(G.nodes()), 3)
depth = math.log(len(G.nodes()), 3) + 1
except:
depth = 0

print (f"{depth=}")
print(f"{depth=}")

# Sort nodes by score and get the top 10
sorted_nodes = Tree.top_n_subsuming_nodes(G, n=4)

print (f"{sorted_nodes=}")
print(f"{sorted_nodes=}")

best_subgraph = None
best_start_node = None
Expand Down
86 changes: 44 additions & 42 deletions web/src/lib/useMuuriGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,67 @@ import Muuri from 'muuri'
// Function to check if a grid is a "full" triangle
function isFullTriangle(grid) {
// Assuming a full triangle grid contains 3 items
console.log("IS FULL TRIANGLE", grid)
console.log('IS FULL TRIANGLE', grid)
if (!grid) return false
return grid.getItems().length >= 3
}
const useMuuriGrid = (gridRef, options, addInstance, removeInstance, size) => {
useEffect(() => {
try {
if (!gridRef.current) return
if (!gridRef.current) return

const grid = new Muuri(gridRef.current, options)
grid.size = size
const grid = new Muuri(gridRef.current, options)
grid.size = size

addInstance(grid)
addInstance(grid)

// Add event listener for dragReleaseEnd event
grid.on('dragReleaseEnd', (item) => {
const oldGrid = item.getGrid()
const newGrid = item._drag._grid
// Add event listener for dragReleaseEnd event
grid.on('dragReleaseEnd', (item) => {
const oldGrid = item.getGrid()
const newGrid = item._drag._grid

// If the item was dragged to a different grid
if (oldGrid !== newGrid) {
// Check if the newGrid is a "full" triangle
if (isFullTriangle(newGrid)) {
// If it's a full triangle, move the item back to the old grid
oldGrid.add(item)
// You may also want to refresh the grid to update the item positions
// If the item was dragged to a different grid
if (oldGrid !== newGrid) {
// Check if the newGrid is a "full" triangle
if (isFullTriangle(newGrid)) {
// If it's a full triangle, move the item back to the old grid
oldGrid.add(item)
// You may also want to refresh the grid to update the item positions

// Calculate the new height
const newHeight = newGrid.size
// Calculate the new height
const newHeight = newGrid.size

console.log({ item, newHeight, gridHeight: newGrid._height, newGrid })
// Set the new height to the item's element
item.getElement().style.height = `${newHeight}px`
item.getElement().style.width = `${newHeight}px`
console.log({
item,
newHeight,
gridHeight: newGrid._height,
newGrid,
})
// Set the new height to the item's element
item.getElement().style.height = `${newHeight}px`
item.getElement().style.width = `${newHeight}px`
// Refresh the old grid to update the item positions
if (oldGrid)
oldGrid.refreshItems().layout()
} else {
// Otherwise, allow the item to be added to the new grid
// You may also want to refresh the new grid to update the item positions
if (newGrid)

newGrid.refreshItems().layout()
if (oldGrid) oldGrid.refreshItems().layout()
} else {
// Otherwise, allow the item to be added to the new grid
// You may also want to refresh the new grid to update the item positions
if (newGrid) newGrid.refreshItems().layout()
}
}
}
})
})

return () => {
// Remove event listener for dragReleaseEnd event
grid.off('dragReleaseEnd')
removeInstance(grid)
try {
grid.destroy()
} catch (e) {
console.log(e)
return () => {
// Remove event listener for dragReleaseEnd event
grid.off('dragReleaseEnd')
removeInstance(grid)
try {
grid.destroy()
} catch (e) {
console.log(e)
}
}
}
} catch (e) {
console.log(e)
console.log(e)
}
}, [gridRef, options, addInstance, removeInstance])
}
Expand Down
5 changes: 4 additions & 1 deletion web/src/ui/BibtexViewer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { toJSON } from 'bibtex-parse-js'

const BibTeXViewer = ({ entry }) => {
const BibTeXViewer = ({ entry, setIsGood, isGood }) => {
let parsedData
console.log(entry)
try {
Expand All @@ -18,6 +18,9 @@ const BibTeXViewer = ({ entry }) => {
// Assuming only one entry for simplicity
const data = parsedData[0].entryTags

if (data.title && !isGood) {
setIsGood(true)
}
return (
<div className="bibtex-entry">
<strong>{data.title}</strong> {data.author}
Expand Down
85 changes: 42 additions & 43 deletions web/src/ui/Puzzle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ const moptions = (size, nest, all_muris) => ({
}
// For the third item, place it at the bottom right
else if (i === 2) {


x = 0
x = 0
y = size * (1 / nest)
}

Expand Down Expand Up @@ -72,12 +70,10 @@ const moptions = (size, nest, all_muris) => ({
event.srcEvent.stopPropagation()
return Muuri.ItemDrag.defaultStartPredicate(item, event)
} catch (e) {
console.log('dragStartPredicate', e)
console.log('dragStartPredicate', e)
}

},
dragSort: () => {

console.log('dragSort', all_muris)
return all_muris
},
Expand Down Expand Up @@ -130,28 +126,33 @@ const MutableTriangle = ({ nest, fullId, data, _key, size }) => {
<div className="puzzle-item-content triangle-content"></div>
{!isLeafNode && data && (
<div ref={gridRef} className="puzzle-grid">
{<MutableTriangle
nest={nest + 1}
fullId={fullId + "3"}
data={data[3] ?? {".": ""} }
_key={fullId + "3"}
size={size / 2}
/> }
{<MutableTriangle
nest={nest + 1}
fullId={fullId + "2"}
data={data[2] ?? {".": ""}}
_key={fullId + "2"}
size={size / 2}
/> }
{<MutableTriangle
nest={nest + 1}
fullId={fullId + "1"}
data={data[1] ?? {".": ""}}
_key={fullId + "1"}
size={size / 2}
/> }

{
<MutableTriangle
nest={nest + 1}
fullId={fullId + '3'}
data={data[3] ?? { '.': '' }}
_key={fullId + '3'}
size={size / 2}
/>
}
{
<MutableTriangle
nest={nest + 1}
fullId={fullId + '2'}
data={data[2] ?? { '.': '' }}
_key={fullId + '2'}
size={size / 2}
/>
}
{
<MutableTriangle
nest={nest + 1}
fullId={fullId + '1'}
data={data[1] ?? { '.': '' }}
_key={fullId + '1'}
size={size / 2}
/>
}
</div>
)}
</div>
Expand All @@ -171,11 +172,7 @@ export const Puzzle = ({

useEffect(() => {
setItems(JSON.parse(JSON.stringify(data)))
}, [data]);




}, [data])

useMuuriGrid(
gridRef,
Expand All @@ -191,16 +188,18 @@ export const Puzzle = ({

return (
<div ref={gridRef} className="puzzle-grid" id="#puzzle-drag-container">
{Object.entries(items).sort(([a], [b]) => b - a).map(([key, item]) => (
<MutableTriangle
key={key}
nest={2}
fullId={key}
data={item}
_key={key}
size={SIZE}
/>
))}
{Object.entries(items)
.sort(([a], [b]) => b - a)
.map(([key, item]) => (
<MutableTriangle
key={key}
nest={2}
fullId={key}
data={item}
_key={key}
size={SIZE}
/>
))}
</div>
)
}
14 changes: 12 additions & 2 deletions web/src/ui/editor/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Editor = () => {
const [state, setState] = useState(null)
const [patch, _setPatch] = useState(null)
const [mods, setMods] = useState(null)
const [activeTab, setActiveTab] = useState('json')
const [activeTab, setActiveTab] = useState('ex')

const [_text, _setText] = useState('')
const [meta, setMeta] = useState('')
Expand Down Expand Up @@ -113,6 +113,7 @@ export const Editor = () => {
console.log('set_mods')
setMods(mods)
})

socket.on('set_task_id', (task_id) => {
if (task_id !== taskId) {
console.log('set_task_id', task_id, task_id)
Expand Down Expand Up @@ -169,6 +170,10 @@ export const Editor = () => {
socket.off('set_hash')
socket.off('set_text')
}
socket.on('refresh', (mods) => {
console.log('set_initial_mods')
setMods(mods)
})
}, [hash, state])

useEffect(() => {
Expand All @@ -182,6 +187,11 @@ export const Editor = () => {
socket.timeout(3000).emit('set_initial_mods')
}, [])

const deleteMod = (hash) => {
console.log('deleteMod', hash)
socket.timeout(3000).emit('delete_mod', hash)
}

return (
<div className="App" style={{ overflowY: 'scroll' }}>
<ShareModal url={'/editor'} linkInfo={{ hash, activeTab }} />
Expand Down Expand Up @@ -243,7 +253,7 @@ export const Editor = () => {
{
key: 'ex',
label: 'Experiments',
children: <ExperimentsView {...{ mods }} />,
children: <ExperimentsView {...{ mods, deleteMod }} />,
},
{
key: 'pz',
Expand Down
Loading

0 comments on commit 2696c93

Please sign in to comment.