Commit Diff


commit - /dev/null
commit + 953b42e64c7ee58655e1e4c4d0f531fe18e31a0c
blob - /dev/null
blob + eb66751f280fec0afe64e25a4b27a13148bc10db (mode 644)
--- /dev/null
+++ pom.xml
@@ -0,0 +1,96 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>twimpact</groupId>
+  <artifactId>midior</artifactId>
+  <version>1.0</version>
+  <inceptionYear>2008</inceptionYear>
+  <properties>
+    <scala.version>2.9.0-1</scala.version>
+  </properties>
+
+  <repositories>
+    <repository>
+      <id>scala-tools.org</id>
+      <name>Scala-Tools Maven2 Repository</name>
+      <url>http://scala-tools.org/repo-releases</url>
+    </repository>
+  </repositories>
+
+  <pluginRepositories>
+    <pluginRepository>
+      <id>scala-tools.org</id>
+      <name>Scala-Tools Maven2 Repository</name>
+      <url>http://scala-tools.org/repo-releases</url>
+    </pluginRepository>
+  </pluginRepositories>
+
+  <dependencies>
+    <dependency>
+      <groupId>twimpact</groupId>
+      <artifactId>twimpact-trending</artifactId>
+      <version>3.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.scala-lang</groupId>
+      <artifactId>scala-library</artifactId>
+      <version>${scala.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <sourceDirectory>src/main/scala</sourceDirectory>
+    <testSourceDirectory>src/test/scala</testSourceDirectory>
+    <plugins>
+      <plugin>
+        <groupId>org.scala-tools</groupId>
+        <artifactId>maven-scala-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>compile</goal>
+              <goal>testCompile</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <scalaVersion>${scala.version}</scalaVersion>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-eclipse-plugin</artifactId>
+        <configuration>
+          <downloadSources>true</downloadSources>
+          <buildcommands>
+            <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
+          </buildcommands>
+          <additionalProjectnatures>
+            <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
+          </additionalProjectnatures>
+          <classpathContainers>
+            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
+            <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
+          </classpathContainers>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.scala-tools</groupId>
+        <artifactId>maven-scala-plugin</artifactId>
+        <configuration>
+          <scalaVersion>${scala.version}</scalaVersion>
+        </configuration>
+      </plugin>
+    </plugins>
+  </reporting>
+</project>
blob - /dev/null
blob + fe1d26e83f45212453bbce426bf3891056cc33cc (mode 644)
--- /dev/null
+++ src/main/scala/twimpact/Midior.scala
@@ -0,0 +1,54 @@
+package twimpact
+
+import io.http.TwitterStream
+import javax.sound.midi.{Sequence, MidiSystem}
+import trending.{MemoryBackend, Timescale, Trevor}
+;
+
+/**
+ * Hello world!
+ *
+ */
+object Midior extends App {
+  val analyzer = new SimpleAnalyzer(new Trevor(new MemoryBackend), Seq(Timescale(300, 10), Timescale(60, 1)))
+
+  // Get default sequencer.
+  val synthesizer = MidiSystem.getSynthesizer
+  synthesizer.open()
+
+  val sequencer = MidiSystem.getSequencer
+  sequencer.open()
+
+  val sequence = new Sequence(Sequence.PPQ, 10)
+  val sb = synthesizer.getDefaultSoundbank
+  val instruments = synthesizer.getDefaultSoundbank.getInstruments
+  synthesizer.loadInstrument(instruments(0))
+
+  var midiChannels = synthesizer.getChannels
+
+  val stream = new TwitterStream("http://dev.twimpact.com/2/stream/retweets.json", false) {
+    username = "twimpactdev"
+    password = "Ywnkmpw."
+  }
+
+  stream.stream(Seq()) {
+    line =>
+      analyzer.tweet.fromJSON(line).foreach {
+        tweet =>
+          analyzer.analyze(tweet).foreach {
+            info =>
+              if (info.score > 1.0) {
+                println("score=%.2f rate=%.2f [user=%s, rank=%.2f] %s"
+                    .format(info.score, info.rate, info.rti.user, info.rank, info.rti.text))
+                val note = 40 + info.score.toInt
+                val reverb = 60 + info.rate.toInt
+                midiChannels(1).noteOff(note)
+                midiChannels(1).noteOn(note, reverb)
+              }
+          }
+      }
+  }
+
+  synthesizer.close()
+  sequencer.close()
+}
blob - /dev/null
blob + a0f83708310b6b869eeec9f94f75930295c0d30f (mode 644)
--- /dev/null
+++ src/main/scala/twimpact/SimpleAnalyzer.scala
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011 TWIMPACT UG (haftungsbeschraenkt). All rights reserved.
+ */
+
+package twimpact
+
+import grizzled.slf4j.Logging
+import trending.{Timescale, TwimpactScore, MultiScaleTrend, Trevor}
+import twitter.{RetweetInfo, Tweet, Twitter}
+
+/**
+ * >>Describe Class<<
+ *
+ * @author Matthias L. Jugel
+ */
+
+case class MidiorInfo(rti: RetweetInfo, score: Double, rate: Double, rank: Double)
+
+class SimpleAnalyzer(trevor: Trevor, timescales: Seq[Timescale], capacity: Map[String, Int] = Map()) extends Twitter(trevor) with Logging {
+  trevor.checkEntityExists("tweet")
+  trevor.checkEntityExists("user")
+  user.setCapacity(capacity.getOrElse("users", 10000))
+
+  val tweets = trevor.createStore[Long, Tweet]("tweets", "tweet")
+  val tweetFifo = trevor.createSimpleTrend[Long]("tweetsFifo", "tweet", "fifo", capacity
+      .getOrElse("tweets", 5000), true)
+
+  var retweetTrend: MultiScaleTrend[Long] =
+    trevor.createMultiScaleTrend[Long]("retweetTrend", "retweet", "exactexpdecay", capacity
+        .getOrElse("trends", 5000), timescales, true)
+  var userRetweetTrend: MultiScaleTrend[String] =
+    trevor.createMultiScaleTrend[String]("userRetweetTrend", "retweet", "exactexpdecay", capacity
+        .getOrElse("trends", 5000), timescales, true)
+
+  var twimpacts = new TwimpactScore[String, Long, Double](userRetweetTrend.scoreTrend(0), 1000, retweetTrend
+      .scoreTrend(0), retweet.retweetsByUser)
+
+  def analyze(tweet: Tweet) = {
+    retweet.analyzeRetweet(tweet) match {
+      case Some(rti) =>
+        tweets.put(tweet.id, tweet)
+        tweetFifo.update(tweet.id)
+
+        val now = tweet.createdAt
+        retweetTrend.update(rti.key, now)
+        userRetweetTrend.update(rti.user, now)
+
+        Some(MidiorInfo(rti, retweetTrend.score(rti.key), retweetTrend.rate(rti.key), twimpacts
+            .computeTwimpact(rti.user)))
+      case None =>
+        None
+    }
+  }
+
+}
\ No newline at end of file