some code to get started

This commit is contained in:
Ward Wouts 2018-03-23 12:30:43 +01:00
parent b0afc0f3e6
commit 7e68ef0f17
4 changed files with 162 additions and 0 deletions

0
lib/__init__.py Normal file
View file

90
lib/causal.py Normal file
View file

@ -0,0 +1,90 @@
import sys
if sys.version_info[0] < 3:
raise "Must be using Python 3"
class Causal:
def __init__(self, causalcode=""):
self.causalcode = causalcode
self._description = ""
self._title = ""
self._prechac = ""
self._sequence = ""
self._fourhanded = ""
# https://docs.python.org/3/library/functions.html#property
@property
def description(self):
return self._description
@description.setter
def description(self, value):
self._description = value
@property
def title(self):
return self._title
@title.setter
def title(self, value):
self._title = value
@property
def prechac(self):
return self._prechac
@prechac.setter
def prechac(self, value):
self._prechac = value
@property
def sequence(self):
return self._sequence
@sequence.setter
def sequence(self, value):
self._sequence = value
@property
def fourhanded(self):
return self._fourhanded
@fourhanded.setter
def fourhanded(self, value):
if self.isvalid_fourhanded(value):
self._fourhanded = str(value)
else:
raise Exception("Can't parse as fourhanded siteswap")
# convert to prechac and fill prechac value
def isvalid_fourhanded(self, value):
if type(value) == int:
value = str(value)
elif type(value) == str:
if value.isdigit():
next
else:
return False
else:
return False
# inspired by https://icculus.org/jugglemaster/docs/validate.txt
lst = [1] * len(value)
for i, c in enumerate(value):
j = ( i + int(c) ) % len(value)
lst[j] = lst[j] - 1
for i in lst:
if i != 0:
return False
return True
def fourhanded_to_local(self, value):
# local notation from https://jonglieren-jena.de/ppa/anthology.pdf
# This is the local siteswap of the pattern accompanying a global siteswap. Subscripts
# indicate the starting positions of the different jugglers. So than in
# A7B65 the juggler A starts with a 7 while B starts with a 6
if not self.isvalid_fourhanded(value):
raise Exception("Can't parse as fourhanded siteswap")
return