Commits

Brendan Howell committed c6b0a4e

showtime

Comments (0)

Files changed (7)

     for i in range(0,len(splitted)):
         if i%2==0:
             processed.append("\n")
-            for s in range(0,(math.sin(i*0.1)+1)*5):
+            for s in range(0,int(round(math.sin(i*0.1)+1)*5)):
                 processed.append(" ")
             linecount=linecount+1
         processed.append(splitted[i])

src/excode.db

Binary file modified.
 ROLE_KEY = "_excd_role"
 CUR_EX_SESSION = "_excd_session"
 
+mungers = ["xtext", "dave", "txtr", "markov", "burroughs"]
+
 class Index:
     _cp_config = {
         'tools.sessions.on': True,
             and_(Round.corpus==corp, Round.round_index==rnd)).first()
 
         #TODO: is this an edit or a new chunk
-        
-        if chunkid:
+        var = random.random()
+        if (var > 0.666):
+            chunks = sqlsession.query(Chunk).filter(Chunk.text != "").all()
+            chunk = random.choice(chunks)
+        elif chunkid:
             chunk = sqlsession.query(Chunk).filter(Chunk.id==chunkid).first()
         else:
-            ant = sqlsession.query(Chunk).filter(Chunk.antecedent == None).first()
+            ant = sqlsession.query(Chunk).filter(Chunk.descendent == None).first()
             name = cherrypy.session.get(USER_KEY)
             author = sqlsession.query(User).filter(User.name==name).first()
             chunk = Chunk("", author, corp, round)
 
             sqlsession.add(chunk)
             sqlsession.flush()
+ 
+            if ant:
+                ant.descendent = [chunk]
 
         if corp.current_round_index < 2:
             lasttext = "no text written yet"
         else:
             lasttext = chunk.antecedent.text
+
+        if len(chunk.descendent):
+            print "Desc EXISTS!"
+            nexttext = chunk.descendent[0].text
+        else:
+            nexttext = None
             
         page = Template(file=template)
         page.corpus = corp
+        page.text = chunk.text
         page.chunkid = chunk.id
         page.lastchunk = lasttext
         #TODO: find next chunk based on descendent
-        page.nextchunk = None
+        page.nextchunk = nexttext
         
         sqlsession.commit()
 
         corp = sqlsession.query(Corpus).filter(Corpus.id==cid).first()
         rnd = corp.current_round_index
         round = sqlsession.query(Round).filter(
-            and_(Round.session==corp, Round.round_index==rnd)).first()
+            and_(Round.corpus==corp, Round.round_index==rnd)).first()
         #TODO: use params for time
 
-        #TODO: munge all texts not just 1
         #munge and update prompts
         chunks = sqlsession.query(Chunk).filter(Chunk.round==round).all()
-        
-        #this is very hacky but allows for dynamic creation of new munge functs
-        mungefunction = eval("munger."+algorithm)
-        munged_output = mungefunction(chunks)
-        round.text_out = munged_output
-        txtout = open("out.txt", "a")
-        txtout.write(munged_output)
-        txtout.close()
+       
+        for chunk in chunks: 
+            #very hacky but allows for dynamic creation of new munge functs
+            var = random.random()
+            if var > 0.666:
+                algorithm = random.choice(mungers)
+                mungefunction = eval("munger."+algorithm)
+                munged_output = mungefunction(chunks)
+                chunk.text_out = munged_output
+            txtout = open("out.txt", "a")
+            txtout.write(chunk.text)
+            txtout.close()
         
         corp.current_round_index = corp.current_round_index + 1
         sqlsession.commit()
-        raise cherrypy.HTTPRedirect("/session?cid="+cid)
+        raise cherrypy.HTTPRedirect("/corpus?cid="+cid)
     
             
     @cherrypy.expose
         
     def __repr__(self):
         return "<Corpus('%s','%s','%s','%s')>" % (self.name, self.creator, 
-                self.current_round, self.total_rounds)
+                self.current_round_index, self.total_rounds)
         
         
 class Round(Base):
         self.round = round
         
     def __repr__(self):
-        return "<Chunk('%s','%s','%s')>" % (self.author, self.round, 
-                self.corpus, self.text)
+        return "<Chunk('%s','%s','%s','%s','%s')>" % (self.author, self.round, 
+                self.corpus, self.text, self.antecedent, self.descendent)
         
         
 
 
 # ${\small \textnormal{\useTextGlyph{fxl}{uni01AE}}}$
 def txtr(chunks):
-    chunk = strip_tags(random.choice(chunks).text)[0:150]
+    chunk = strip_tags(random.choice(chunks).text)[0:170]
     chunk = chunk.replace("a", "")
     chunk = chunk.replace("e", "")
     chunk = chunk.replace("i", "")

src/templates/corpus.tmpl

     <h3>round $corpus.current_round_index</h3>
     <h3>antecedent chunk:</h3>
     <p style="font-style:italic;">$lastchunk</p>
+    <div id="hideMsg"><span>600</span> seconds remaining</div>
     <h3>write:</h3>
-    <form action="addchunk" method="POST">
-        <textarea name="text" style="width:100%">
+    <form id="chunkform" action="addchunk" method="POST">
+        <textarea name="text" style="width:100%">$text
         </textarea>
         <input type="hidden" name="cid" value="$corpus.id" />
         <input type="hidden" name="chunkid" value="$chunkid" />
     <h3>decendent chunk:</h3>
     <p style="font-style:italic;">$nextchunk</p>
     #end if
+    <script type="text/javascript">
+	var sec = 600;
+	var timer = setInterval(function() {
+	   jQuery('#hideMsg span').text(sec--);
+	   if (sec == -1) {
+	      jQuery('#hideMsg').fadeOut('fast');
+	      clearInterval(timer);
+              jQuery('#chunkform').submit();
+	   }
+	}, 1000);
+    </script>
 #include "templates/footer.tmpl"

src/templates/header.tmpl

 	  theme_advanced_buttons2 : "",
 	  theme_advanced_buttons3 : "",
           theme_advanced_toolbar_align : "left",
+          theme_advanced_statusbar_location : 'bottom',
           theme_advanced_resizing : true
 	});
 	</script>