Пример #1
0
def load(filename):
    f = open(filename)
    try:
        json_object = json.load(f)
    except:
        raise InvalidFileFormat, "Need JSON file!"
    f.close()

    if not "file_type" in json_object or not json_object[
            "file_type"] == FILE_TYPE:
        raise InvalidFileFormat, "Invalid JSON file."

    if not json_object["format_version"] == FILE_FORMAT_VERSION:
        raise InvalidFileFormat, "Got file format version %s, need version %s" % (
            json_object["format_version"], FILE_FORMAT_VERSION)

    # collect strings from tabulature
    strings = [i["tuning"] for i in json_object["tabulature"]]

    project = Project(json_object["audiofile"], strings, filename)

    for json_marker_object in json_object["markers"]:
        marker = Timeline.Marker(project.timeline,
                                 json_marker_object["start"],
                                 json_marker_object["duration"],
                                 json_marker_object["text"],
                                 x=json_marker_object["x"])
        project.timeline.markers.append(marker)

    for i in xrange(len(json_object["tabulature"])):
        json_string_object = json_object["tabulature"][i]

        for json_marker_object in json_string_object["markers"]:
            string = project.timeline.tabulature.strings[i]
            marker = Timeline.TabMarker(string, json_marker_object["start"],
                                        json_marker_object["duration"],
                                        json_marker_object["fret"])
            string.markers.append(marker)

    for json_annotation_object in json_object["annotations"]:
        marker = Timeline.Annotation(project.timeline,
                                     x=json_annotation_object["x"],
                                     time=json_annotation_object["time"],
                                     text=json_annotation_object["text"])
        project.timeline.annotations.append(marker)

    for json_tap_object in json_object["rhythm"]:
        time = json_tap_object["time"]
        tap = Timeline.Tap(project.timeline.rhythm,
                           json_tap_object["weight"],
                           time=time)
        project.timeline.rhythm.taps.append(tap)

    project.touched = False

    return project
Пример #2
0
    def __init__(self, anim_):
        self.anim = anim_
        # This is the time line object that if at to bottom of
        # the screen.
        self.timeline = Timeline(self.anim)
        # The list of all the user's objects
        self.animlist = []

        # This stores the Z order list of items at a given time.
        # The key is the time (number) and the value is
        # a list of items id in the order they appear on screen.
        self.zorder = {}

        # Create our rootitem. We put each canvas item in it so at the end we
        # only have to kill it. The canvas deletes all the items it contains
        # automaticaly.
        self.rootitem = goocanvas.Group(
            parent=self.anim.gcomprisBoard.canvas.get_root_item())

        self.pickle_protocol = 2
        self.format_string = {'gcompris': 'GCompris anim 3 cPikle file'}
Пример #3
0
    def __init__(self, audiofile, strings=None, filename=None):
        self.filename = filename
        self.audiofile = audiofile
        self.touched = True

        if not strings: strings = [-5, -10, -14, -19, -24, -29]

        self.appsinkpipeline = Pipeline.AppSinkPipeline(self.audiofile)
        self.pipeline = Pipeline.Pipeline(self.audiofile)
        self.timeline = Timeline.Timeline(self, strings)
        self.timeline.show_all()
        self.control = VisualizerControl(self.pipeline)
Пример #4
0
  def __init__(self, anim_):
    self.anim = anim_
    # This is the time line object that if at to bottom of
    # the screen.
    self.timeline = Timeline(self.anim)
    # The list of all the user's objects
    self.animlist = []

    # This stores the Z order list of items at a given time.
    # The key is the time (number) and the value is
    # a list of items id in the order they appear on screen.
    self.zorder = {}

    # Create our rootitem. We put each canvas item in it so at the end we
    # only have to kill it. The canvas deletes all the items it contains
    # automaticaly.
    self.rootitem = goocanvas.Group(
      parent =  self.anim.gcomprisBoard.canvas.get_root_item())

    self.pickle_protocol = 2
    self.format_string = { 'gcompris' : 'GCompris anim 3 cPikle file' }
Пример #5
0
class Document:
    """This holds everything releated to the animation itself"""
    def __init__(self, anim_):
        self.anim = anim_
        # This is the time line object that if at to bottom of
        # the screen.
        self.timeline = Timeline(self.anim)
        # The list of all the user's objects
        self.animlist = []

        # This stores the Z order list of items at a given time.
        # The key is the time (number) and the value is
        # a list of items id in the order they appear on screen.
        self.zorder = {}

        # Create our rootitem. We put each canvas item in it so at the end we
        # only have to kill it. The canvas deletes all the items it contains
        # automaticaly.
        self.rootitem = goocanvas.Group(
            parent=self.anim.gcomprisBoard.canvas.get_root_item())

        self.pickle_protocol = 2
        self.format_string = {'gcompris': 'GCompris anim 3 cPikle file'}

    def __del__(self):
        self.rootitem.remove()

    def refresh(self, time):
        # We keep all object in a unique list
        # Here we call them to give them a chance to
        # display them if they have to
        for item in self.animlist:
            item.display_at_time(time)
        self.restore_zorder()

    # If an item is removed, we must remove it from all
    # the timelines in which we saved a z_order
    def delete_from_zorder(self, item_id):
        for z_order in self.zorder.values():
            try:
                z_order.remove(item_id)
            except ValueError:
                pass

    def save_zorder(self):
        z_order = []
        for i in range(self.rootitem.get_n_children()):
            item = self.rootitem.get_child(i)
            if item.props.visibility == goocanvas.ITEM_VISIBLE:
                z_order.append(item.get_data("id"))

        self.zorder[self.timeline.get_time()] = z_order

    def restore_zorder(self):
        z_order = []
        if self.timeline.get_time() in self.zorder:
            z_order = self.zorder[self.timeline.get_time()]
        for i in range(self.rootitem.get_n_children()):
            item = self.rootitem.get_child(i)
            if item:
                item_id = item.get_data("id")
                try:
                    z_index = z_order.index(item_id)
                    self.rootitem.move_child(i, z_index)
                except ValueError:
                    pass

    def anim_to_file(self, filename):

        file = open(filename, 'wb')

        # Save the descriptif frame:
        pickle.dump(self.format_string['gcompris'], file, self.pickle_protocol)

        # Save the last mark
        pickle.dump(self.timeline.get_lastmark(), file, self.pickle_protocol)

        # Save the animation
        pickle.dump(self.animlist, file, self.pickle_protocol)

        # Save the z order
        pickle.dump(self.zorder, file, self.pickle_protocol)

        file.close()

    def file_to_anim(self, filename):

        file = open(filename, 'rb')
        try:
            desc = pickle.load(file)
        except:
            file.close()
            print 'Cannot load ', filename, " as a GCompris animation"
            return

        if type(desc) == type('str'):
            # string
            if 'desc' != self.format_string['gcompris']:
                if (desc == 'GCompris anim 3 cPikle file'):

                    self.anim.deselect()
                    for item in self.animlist[:]:
                        item.delete()

                    self.timeline.set_lastmark(pickle.load(file))
                    self.animlist = pickle.load(file)
                    for item in self.animlist:
                        item.restore(self.anim)

                    self.zorder = pickle.load(file)

                    # Restore is complete
                    self.timeline.set_time(0)
                    self.refresh(0)
                else:
                    print "ERROR: Unrecognized file format, file", filename, ' has description : ', desc
                    file.close()
                    return
            else:
                print "ERROR: Unrecognized file format (desc), file", filename, ' has description : ', desc
                file.close()
                return

        elif type(desc) == type(1):
            print filename, 'has no description. Are you sure it\'s', \
                self.format_string['gcompris'],'?'

        file.close()
Пример #6
0
class Document:
  """This holds everything releated to the animation itself"""

  def __init__(self, anim_):
    self.anim = anim_
    # This is the time line object that if at to bottom of
    # the screen.
    self.timeline = Timeline(self.anim)
    # The list of all the user's objects
    self.animlist = []

    # This stores the Z order list of items at a given time.
    # The key is the time (number) and the value is
    # a list of items id in the order they appear on screen.
    self.zorder = {}

    # Set to true when the order or the list of object has changed
    self.zorderDirty = False

    # Create our rootitem. We put each canvas item in it so at the end we
    # only have to kill it. The canvas deletes all the items it contains
    # automaticaly.
    self.rootitem = goocanvas.Group(
      parent =  self.anim.gcomprisBoard.canvas.get_root_item())

    self.pickle_protocol = 2
    self.format_string = { 'gcompris' : 'GCompris anim 3 cPikle file' }

  def __del__(self):
    self.rootitem.remove()

  def refresh(self, time):
    # We keep all object in a unique list
    # Here we call them to give them a chance to
    # display them if they have to
    for item in self.animlist:
      item.display_at_time(time)
    self.restore_zorder()


  def zorder_dirty(self):
    self.zorderDirty = True

  def save_zorder(self):
    if not self.zorderDirty:
      return

    z_order = []
    for i in range(self.rootitem.get_n_children()):
      item = self.rootitem.get_child(i)
      if item.props.visibility == goocanvas.ITEM_VISIBLE:
        z_order.append(item.get_data("id"))

    self.zorder[self.timeline.get_time()] = z_order
    self.zorderDirty = False

  def restore_zorder(self):
    z_order = []
    if self.timeline.get_time() in self.zorder:
      z_order = self.zorder[self.timeline.get_time()]
    else:
      return

    # Build the list of items_is present in the image
    present_items = []
    for i in range(self.rootitem.get_n_children()):
      item = self.rootitem.get_child(i)
      if item:
        present_items.append( item.get_data("id") )

    # Remove items in z_order that are not in present_items
    z_order = [item for item in z_order if item in present_items]

    for z_item_id in z_order:
      for i in range(self.rootitem.get_n_children()):
        item = self.rootitem.get_child(i)
        if item:
          item_id = item.get_data("id")
          if ( item_id == z_item_id ):
            z_index = z_order.index(item_id)
            if ( i != z_index ):
              try:
                self.rootitem.move_child(i, z_index);
                break
              except ValueError:
                pass

  def anim_to_file(self, filename):

    file = open(filename, 'wb')

    # Save the descriptif frame:
    pickle.dump(self.format_string['gcompris'], file, self.pickle_protocol)

    # Save the last mark
    pickle.dump(self.timeline.get_lastmark(), file, self.pickle_protocol)

    # Save the animation
    pickle.dump(self.animlist, file, self.pickle_protocol)

    # Save the z order
    pickle.dump(self.zorder, file, self.pickle_protocol)

    file.close()


  def file_to_anim(self, filename):

    file = open(filename, 'rb')
    try:
      desc = pickle.load(file)
    except:
      file.close()
      print 'Cannot load ', filename , " as a GCompris animation"
      return

    if type(desc) == type('str'):
      # string
      if 'desc' != self.format_string['gcompris']:
        if (desc == 'GCompris anim 3 cPikle file'):

          self.anim.deselect()
          for item in self.animlist[:]:
            item.delete()

          self.timeline.set_lastmark(pickle.load(file))
          self.animlist = pickle.load(file)
          for item in self.animlist:
            item.restore(self.anim)

          self.zorder = pickle.load(file)

          # Restore is complete
          self.timeline.set_time(0)
          self.refresh(0)
        else:
          print "ERROR: Unrecognized file format, file", filename, ' has description : ', desc
          file.close()
          return
      else:
        print "ERROR: Unrecognized file format (desc), file", filename, ' has description : ', desc
        file.close()
        return

    elif type(desc) == type(1):
      print filename, 'has no description. Are you sure it\'s', \
          self.format_string['gcompris'],'?'

    file.close()
 def toCartesian(self, latitude, longitude, height):
     return Timeline.toCartesian(latitude, longitude, height)
Пример #8
0
def main():
    global window, scene

    glutInit(sys.argv)

    # Select type of Display mode:   
    #  Double buffer 
    #  RGBA color
    # Alpha components supported 
    # Depth buffer
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
    
    # get a 640 x 480 window 
    glutInitWindowSize(960, 480)
    
    # the window starts at the upper left corner of the screen 
    glutInitWindowPosition(0, 0)
    
    # Okay, like the C version we retain the window id to use when closing, but for those of you new
    # to Python (like myself), remember this assignment would make the variable local and not global
    # if it weren't for the global declaration at the start of main.
    window = glutCreateWindow("ACCRE Cluster Status Monitor")

    # Register the drawing function with glut, BUT in Python land, at least using PyOpenGL, we need to
    # set the function pointer and invoke a function to actually register the callback, otherwise it
    # would be very much like the C version of the code.    
    glutDisplayFunc(DrawGLScene)
    #glutDisplayFunc()
    
    # Uncomment this line to get full screen.
    # glutFullScreen()

    # When we are doing nothing, redraw the scene.
    glutIdleFunc(doIdle)
        
    # Register the function called when our window is resized.
    glutReshapeFunc(ReSizeGLScene)

    # Register the function called when the keyboard is pressed.  
    glutKeyboardFunc(keyPressed)
    
    glutMouseFunc( mousePressed )
    
    # Load the stages
    storageStage   = StorageStage()
    globeStage     = TexturedGlobe()

    LHCStatusStage = CurlStage( pos = [40.9604490329, 580.455382799, 797.001287513],
                                url = "http://vistar-capture.web.cern.ch/vistar-capture/lhc1.png",
                                updateRate = 160 * 1000)
    DAQStatusStage = CurlStage( pos = [36.9604490329, 580.455382799, 797.001287513],
                                url = "http://cmsonline.cern.ch/daqStatusSCX/aDAQmon/DAQstatusGre.jpg",
                                updateRate = 150 * 1000)
    CMSStatusStage = CurlStage( pos = [32.9604490329, 580.455382799, 797.001287513],
                                url = "http://cmspage1.web.cern.ch/cmspage1/data/page1.png",
                                updateRate = 180 * 1000)
    
    scene['camera'].lookat = LHCStatusStage.pos
    scene['camera'].pos = [40.9604490329, 580.455382799, 799.001287513]
     
    scene['objects'].extend( [storageStage, globeStage, LHCStatusStage, DAQStatusStage, CMSStatusStage] )
    
    globalCameraTween    = MoveCameraTween( scene['camera'], [137.74360349518597, 1769.5965518451512, 2418.585277263117],
                                            [0,0,0],[0,1,0] )
    
    #globalViewTween = RotateCameraTween( scene['camera'], 36.1658, -86.7844, 3000, 1, [0,0,0], [0,1,0])
    globalViewTween = RotateCameraTween( scene['camera'], 36.1658,-86.7844, 3000, 1, [0,0,0], [0,1,0])

    storageCamTween  = MoveCameraTween( scene['camera'],
                                             [45.9604490329, 580.455382799, 799.001287513],
                                             [45.9604490329, 580.455382799, 797.001287513],
                                             [0,1,0] )

    
    hideGlobe = HideTween( [ globeStage] )
    showGlobe = ShowTween( [ globeStage] )
    
    storageTimeline = Timeline( name = "Vampire - Storage")
    storageTimeline.tweens.append( storageCamTween )
    storageTimeline.tweens.append( hideGlobe )
    storageToGlobal = Timeline( name = "Zoom to world")
    storageToGlobal.tweens.append( globalCameraTween )
    storageToGlobal.tweens.append( showGlobe )
    globalTimeline  = Timeline( name = "CMS - Global")
    globalTimeline.tweens.append( globalViewTween )
    #globalTimeline.duration = 50000
    globalToStorage = Timeline( name = "Zoom to ACCRE")
    globalToStorage.tweens.append( storageCamTween )
    
    plotsToMonitor = ["http://vistar-capture.web.cern.ch/vistar-capture/lhc1.png",
                      "http://cmsonline.cern.ch/daqStatusSCX/aDAQmon/DAQstatusGre.jpg",
                      "http://cmspage1.web.cern.ch/cmspage1/data/page1.png"]
    initialPlotPos = [40.9604490329, 580.455382799, 797.001287513]
    previousTimeline = storageTimeline
    for plot in plotsToMonitor:
        stage = CurlStage( pos = initialPlotPos,
                                url = plot,
                                updateRate = 160 * 1000)
        
        plotSwapTween  = MoveCameraTween( scene['camera'],
                                             Vectors.add(stage.pos, [0,0,2]),
                                             stage.pos,
                                             [0,1,0],
                                             arrivalAlpha = 0.1 )
        currentTimeline = Timeline( name = "Monitoring Plots")
        currentTimeline.tweens.append( plotSwapTween )
        previousTimeline.setNext( currentTimeline )
        previousTimeline = currentTimeline
        initialPlotPos = Vectors.add(initialPlotPos, [-4,0,0])

    currentTimeline.setNext(storageToGlobal)
    storageToGlobal.setNext( globalTimeline )
    globalTimeline.setNext(  globalToStorage )
    globalToStorage.setNext( storageTimeline )
    
    scene['currentTimeline'] = globalTimeline
    globalTimeline.start( 0 )
    # Initialize our window. 
    InitGL(960, 480)
Пример #9
0
    matchObj = re.match(r'(.*)\.pdf', filename)
    if matchObj:
        try:
            docname = matchObj.group(1)
            if docname+"_out.txt" not in os.listdir(data):
                print "Retrieving text of",docname
                pdf2txt.pdf_to_file(data+os.sep+filename, data+os.sep+docname+"_out.txt")
        except:
            print "Problem getting the name of the file \"",filename,"\"."


#Constructing TFIDFMatrixes for every concerned time period
periodFrequenciesList=[]
matrixList=[]
authorName=argv[1]
startDate=Timeline.formatDate(argv[2])
endDate=Timeline.formatDate(argv[3])
startDateTime=date(int(str(startDate).split()[0]),int(str(startDate).split()[1]),1) #conversion to objects of type dateTime
endDateTime=date(int(str(endDate).split()[0]),int(str(endDate).split()[1]),1)
periodLength=int(argv[4])
periodNumber2=monthdelta(startDateTime,endDateTime)//periodLength #number of periods considered
date1=startDateTime
date2=date1+ relativedelta(months=+periodLength)

for i in range(periodNumber2+1):  #create TFDIDF Matrixes for each period
    print i
    m=dataTimeline.createTFIDFMatrix(authorName, date1, date2, 
            variables.data_dir + os.sep + bibName) #TFIDF Matrix with all words/concepts.
#    tops = m.weights(number=5) #dictionary {concept:weight} for the top 5 five concepts, weight of best concept = 100, least = 1
    matrixList.append(m)
    date1=date2