Moments Journal object and functions related to using journals
A journal holds a collection of Moments (and Entries, for moments with no timestamps)
Main Moments module for collecting Moment entries in one place
*2011.06.26 13:50:20 not sure that it even makes sense to base this on a standard list should use a list internally but we really don’t use any of the methods for a list to interact with a Journal object
so we could have self._entries self._tags self._dates
to store everything internally and then use custom methods for interacting with the Journal these methods should be the same whether the Journal is a local, native, instance, or if it is remote.
i.e. using journal object attributes directly in code is discouraged to ensure that local and remote journal objects work identically
add a new property to the Journal: datas at one point this was generated automaticaly, but that slowed things down
this allows it to be generated when it is needed which so far is only when then node.directory object is looking for a default image
add a new property to the Journal: files similar to associate_datas
but checks each entry’s data for path information if path is found just take the filename portion and associate the entry with that portion
otherwise associate each line of the entry’s data (as is)
clear mind start fresh
in practice it’s probably easier to just create a new journal but reload might need this
return a dictionary with: all dates as keys, and number of entries for each date as values
return a list of entries making a function call rather than an attribute to make consistent between local and remote calls
return the item at index point in list is this already defined on a list object? should be consistent
adds a log file to the journal object currently in memory
this can be called multiple times with different filenames to merge those files/entries into the journal
>>> from journal import *
>>> j = Journal()
>>> j.load("sample_log.txt")
>>> len(j.entries)
1
return True if the file was able to be loaded False if it was not a journal/Log file
load the first entry tagged instance_name from the instance file
helper for making a new entry right in a journal object this way should not need to import moments.entry.Entry elsewhere
if no start and end specified return the time range for the entries in the currently loaded journal
if only start return the entries in range for the accuracy of the start (e.g. 1 day)
if start and end return all entries in the journal that fall in that range
should accept a string, a datetime object, or a Timestamp object
look for tags if no matching tags see if it is a date string (get range, find entries there)
either way return tags that are related (maybe as a dictionary {‘tag’:number_of_items} ...
same as self._tags)
create a new instance of a journal based on the paths we have previously loaded (self.loaded)
load everything that was previously loaded then swap out the contents old journal for the new one
remove associations from self._dates and self._tags then remove the entry from the journal.
>>> from entry import Entry
>>> e = Entry("test entry")
>>> j.add_entry(e)
>>> j.to_file("sample_log2.txt")
>>> k = Journal()
>>> k.load("sample_log2.txt")
>>> len(k.entries)
2
loop through all self.sources or self.loaded and save the corresponding entries back (only if there is an actual change???)
might want to return any entries that don’t have a destination or would it be better to return an error? or not save if entries don’t have a destination
scan tags for tags matching (searching) look_for if data is True, look in entry.data too
Sorts the items in our Journal’s ._entries list
returns a list of the rearranged order of the entries in the journal
can specify order:
‘original’ to keep the original order that the entries were added to the journal
‘reverse’
‘chronological’ or ‘oldest to newest’ oldest entries first in the list
‘reverse-chronological’ or ‘newest to oldest’
if not all entries are wanted, see self.range()
lookup tag_key in self._tags
should only return a list of entries associated with that tag not a dict with the tag name server can do that but server needs to be a little different
return a dictionary with: all tags as keys, and number of entries for each tag as values
*2011.07.10 10:38:07 also could use mindstream.entries_tagged to accept a list of tags and combine all of those entries into a single list and return that
checks if an entry already exists in the journal if other entries in with that time stamp are similar, see if they can be merged easily (i.e. only tags differ)
otherwise just add it as a separate entry no longer attempting to choose which one to keep here since journal can hold multiple entries with the same timestamp
can merge later as needed using dedicated script for that purpose
This is a drop in replacement for Journal but rather than load and store the data in an internal data structure all information is retrieved from a journal_server using json
ultimately this avoids needing to reload a large journal set when working on applications to leverage information in a journal.
wraps calls to a journal_server to make the object interaction behave the same as a local Journal object
Uses the following calls for GET and POST requests:
POST: req = urllib2.urlopen(url, params) GET: req = urllib2.urlopen(url)
returns a dictionary of tags (with count) if no item specified otherwise returns a list of moments for item specified