Wednesday, May 12, 2010

Plasma & the libferris DataEngine

In a previous post I mentioned that libferris can now mount Plasma DataEngines. Of course, the opposite would have to follow; you can now access the entire virtual filesystem of libferris as a Plasma DataEngine. For those who are unfamiliar with libferris, it is my little virtual filesystem project which can mount xml, isam files, relational databases, flickr, vimeo, google spreadsheets, Firefox, XWindows, and shall we say one or two other things :)

To play around, I now have a DataEngine that ships with libferris itself (which exposes libferris to plasma), and a few custom plasmoids which basically ask the libferris data engine to "cat" files and metadata.

One of the things that libferris can mount is the XWindow system. This lets you see all your windows and their size and location. This data is exposed in xwin://localhost/window and the Extended Attributes (EA) x,y show the x and y position of each window. For example, the below command will show you the name and location of the window "foo" on your local X:
fls --show-ea=name,x,y xwin://localhost/window/foo

The libferris data engine makes "sources" on demand. You ask for a source by supplying the URL you want to read, the data engine makes the source for you and the content key contains the contents of that URL. If you want to get at metadata through the EA interface, just use @attribute in XML fashion.

The two plasmoids I made are libferris_cat and libferris_graph. The former just shows you text of the URL you have configured, the latter allows up to four files to be read and graphed. Obviously the latter plasmoid is meant for numeric data.

So to see the location of a window with ferris_cat set the URL to:
xwin://localhost/window/foo@x

Which is what I've done in the below video. Notice that there are two plasmoids so I can track the X and Y ordinates of the window as I move it.

plasma-cat-window-position-encoded.avi from Ben Martin on Vimeo.



The same data is shown using ferris_graph below.

plasma-graph-window-position-encoded.avi from Ben Martin on Vimeo.



Libferris can also mount postgresql and other relational databases. For postgresql you can run SQL and execute database functions through the filesystem as well as interact with the base tables. Lets assume you have a simple database like the one shown in the below setup:

drop database testplasma;
create database testplasma;
\c testplasma

create table folks ( name varchar, salary int, id serial );
create view stats as
select min(salary) as min, max(salary) as max, avg(salary) as avg
from folks;

insert into folks values ( 'Fred', 15 );
insert into folks values ( 'Mary', 17 );
insert into folks values ( 'Henry', 21 );

select * from stats;
min | max | avg
-----+-----+---------------------
15 | 21 | 17.6666666666666667
(1 row)

To get at this with libferris you might start by probing around the pg:// or postgresql:// URLs:

fls pg://localhost/testplasma
folks stats

fls -0 pg://localhost/testplasma/stats
15 21 17.6666666666666667 17.6666666666666667-21-15 avg-max-min
Adding the --xml switch to shows something including:
avg="17.6666666666666667" max="21" min="15"
name="17.6666666666666667-21-15" primary-key="avg-max-min"

Because the view has no primary key, libferris has used the values of the whole tuple to form a unique file name. This is less than optimal for our needs when using the DataEngine because we want a stable filename. The solution is to leave out the name and just use "*" to have libferris expand it for us! So the below URL will have ferris_cat track the "min" value in the view:
pg://localhost/testplasma/stats/*@min

The below video shows ferris_cat on the left viewing the min, the ferris_graph in the center shows min, max and average, and the avg is shown in the ferris_cat on the right. I add and remove a few folks from the table to see the effect on the plasmoids.

plasma-ferris-postgresql-encoded.avi from Ben Martin on Vimeo.



Of course, for a production PostgreSQL server you would use a scratch table and triggers to update it so that aggregates are not computed over mid to large sized tables all the time. Another advantage of triggers and a scratch table is you can easily handle rolling averages and delve into more advanced statistics while keeping the overhead known.

In short, if you can ferrisls and fcat something interesting, you should be able to drop it onto your desktop and monitor it now too :) All I need now is to get plasma onto my n810 :/ I have a feeling I'll be playing with tracking facebook and online spreadsheets using plasma+ferris soon ;p

Saturday, May 8, 2010

Desktop Annotations...

OK, so a post about annotating files and desktop search. KDE guys might be interested because libferris uses soprano, the base of RDF on that desktop, maemo guys might be interested because all this works on that platform too, and I have a specialized index structure for n810 power level devices in libferris.

Tagging and Annotations are closely related. Tags (or emblems in libferris terms) are great for assigning one or more concepts to a file.
Annotations are great for adding some free text to something. While a short annotation might seem like one, two, or three tags, as in the example below, annotations also carry linguistic weight. Normally with tags you don't care about the order the tags are added to the file. With an annotation and a full text index you should be able to do proximity matching and ordered searching "seed collection" matches but "collection seed" doesn't. There are also issues of human language stemming which many tag systems silently ignore but full text indexes tend to have to address.

Below is the ego file manager 0.30.0 with the Annotation side panel. This panel auto saves the annotation if you select a new file or if you stop changing it for a few seconds. Hotkeys make this all quite handy. I'm using Control-t to start interactive tagging and Control-6 to switch to the annotation sidepanel with focus in the text block there. Hitting tab in the annotation sidepanel moves focus to the file list, so you can skip to and from annotating each file without the rodent.


You can of course add, view, and edit these same annotations from the command line. The fedit command runs vi on the annotation, allowing you to freely change it.
I have just fixed a slight inconsistency in the fedit command so it now accepts the "-a attribute" option too. The fcat views the annotation "-a attribute" from the file.

$ >| tfile
$ fedit -a annotation tfile
...
$ fcat -a annotation tfile
hi, the new annotation

$ feaindexquery '(annotation=~new)'
Found 1 matches at the following locations:
file:///tmp/tfile

Another nifty trick is to see the annotation right inside an fls output. Use mtime-display if you want the time to be more human readable than an epoch time_t.

$ fls --show-ea name,size,mtime,annotation tfile
tfile 0 1265954823 hi, the new annotation

Remember also that fls --xml gives you XML output, so with an XSLT stylesheet you can serve a directory of files and their annotation through your web server.
If this is of interest, see apps/phpsearchinterface/xml-results-to-xhtml.xsl for an initial stylesheet with row colour striping. It should be easy to extend the stylesheet to present other attributes. Bonus marks for anyone who makes it handle arbitrary XML attributes and orders them according to a predefined POSET. Patches always welcome...

When libferris saves an annotation, if DBus is enabled a signal is emitted on the session bus: "org.libferris.desktop", "AnnotationSaved"
which carries the URL and Path for the file you changed. This allows not only reindexing to happen, but you are free to hook up some Perl or whatnot to monitor this signal, then you can actually run some logic to work out what to do. If an annotation is saved, you might like to update an RSS feed for example.

And so ends the libferris tip of the day... happy annotating!
This post has been fueled by 99% cocoa, thanks to Jan-Piet Mens ;-)

Thursday, May 6, 2010

Plasma: Tree Shaped Eyes

After digging into KDE4's plasma a little bit it smelt a bit like an old friend. In Plasma you have one or more data engines, and each engine can have many sources. Each source offers a list of key-value pairs, which are updated at a nominated interval.

Normally folks think of filesystems as directories and files. But these days, you have to consider the Extended Attribute (EA) interface that filesystems offer as well. This makes a filesystem much closer to a large XML repository than just a collection of files accessible through a tree namespace (the directories). In libferris, each EA key-value pair can also tell the developer/user what schema that value has. This closes the gap between what a filesystem is and what a plasma data engine is just a little bit more. In fact, one might think of a plasma data engine as a virtual filesystem with a touch of extra stuff to allow a plasmoid to poll the data engine easily. This is not to detract from plasma at all, saying its "just a filesystem" means it is like postgresql, xml, or emacs to me ;)

For example, to see some current weather using my ABOMiNation plasma data engine and libferris (dev trunk), I can see the wind and also what type of value that EA or data engine key-value is:


$ fls -l \
--show-ea=name,air-temp,wind-speed,wind-gust,schema:wind-gust \
plasma://abomination_observations/nnn1

nnn1 22 15 26 schema://xsd/attributes/decimal/integer/long/int


One major upshot of looking at plasma in this way is the major upshot of everything being a filesystem. I can "cat" values directly from a data engine and also use fls to inspect data engines and their values from the command line while developing. plasmaengineexplorer is very nice, but its a bit of a pain to use a GUI tool to test out if the data engine is working when you are in a compile, run test cycle. It is also really easy to pluck out data from plasma with libferris, for example, the above fls with a --xml on the command line will do what you imagine. And if you are a nepomuk fan, using fls --rdf will give you an RDF/XML file to enjoy.

I found a few of the data engines would crash if they are started with a QApplication that forces GUI to off. So I black list
s == "tasks" || s == "mouse" || s == "keystate"
in order to mount plasma at the moment. Also, I'm using the signal/slot callbacks to get at the source key-value hash because the immediate mode methods don't seem to want to work for me :/

Tuesday, April 27, 2010

Plasma: Environmental Awareness

Last time around I mentioned the plasmoids I finally decided to write to show information from the Australian Bureau of Meteorology, or BOM as it's lovingly known in some circles. I have put in place a few more touches to make it useful and have been experimenting with it since the last post. Shown below is the updated radar view which uses a custom background image and a modified locations overlay. The sat images are from Google Maps.

This gave me the idea that this particular plasmoid should be "Environmental" instead of just weather. If there is a crash on the north bound road that you use, seeing a little red dot there would be great. Having it pulse when you animate the radar would also be good so you have a much greater chance of seeing it. Likewise, for bus and train services, seeing which lines of interest are inactive due to track work or where delays are. It is more about showing things that are of interest today than just the weather.

I'm thinking that using Marble and Nepomuk (RDF) here would be the way to go. Telling marble that the doppler radar images are for dlong/dlat and extend to dlong/dlat should be OK for overlaying them. Nepomuk would be the way to go for harvesting the other information, like the delays or traffic reports and if they are properly geotagged, perhaps geo84, then a sparql should be able to bring them to the map. Of course, a timeline slider would then live on the top so you can see things that might have happened but been already resolved.

My mind's eye could see the benefit to the gust / average wind speed vs time plot plasmoid, but now that I have had it running for a while I can also show folks that I wanted... as you can see, looking at the plasmoid on the right, the red is the average wind speed and the blue extends to the gust speed. It becomes obvious not only if it is breezy, but if there is a large amount of variability in the wind. This metric is very important to some activities that are sensitive to wind. For weather geeks, the drop in wind should also show in the temp graph on the left because the apparent temp will alter as well. Though at 16C with winds < 10km/h it is to small to really see. BTW I know that the times are wrong in the title, there is an erroneous UTC offset happening to that epoch somewhere along the lines it seems.


I am not fully happy with the Forecast view. The icons and max temps for today and tomorrow are shown on the left and the detailed text on the right. It is very hard to show the detailed BOM text graphically, as things like "Chance of a late storm" require strange combinations of the "Fine" and "Storm" icons from the KDE set, and that doesn't take into account the "chance of" part in the text forecast.


These will likely be shoved into KDE's svn as aaron suggested. If anyone feels strongly _against_ that choice then please ping me, otherwise I'll assume sunshine and lolly pops.

Monday, April 26, 2010

Plasma: It's an abomination I tell's ya...

Now that I have your attention and defences up, abomination is the name of my new plasmoids for showing the Australian Bureau of Meteorology (ABOM) National weather info, thus it is an ABOMiNation. Yes, my humour is offered for free, though you die a little with each joke.

Things are split up into Perl scripts, data engines, and plasmoids. Its still version 0.0.1 so expect a reading of the README and a bit of tinkering to get going.

One of the nice things is that the radar image loop can be offered on the desktop with just the latest doppler radar overlay. As the background, topographic and locations are all separate PNGs you can easily get a custom look and feel or theme for your version too.


Observations are downloaded for your nominated cities. The observations plasmoid can show the ambient and apparent temperature, wind average and gust speeds, and rainfall on a rolling graph. These screenshots were taken with a sample time of 1 second and a random multiplier to test, in reality you should see nicer bell like curves for temps and less sporadic curves for wind. Seeing the gust as a cumulative on the same graph is handy for motorbike riders so you can see how "choppy" things are at a glance. Especially if you have observations for other places that you are heading towards which might be 100-200km away from your abode. For temps as shown below the -1 as the offset to apparent temp from ambient temp. The time is always when the latest observation was taken.

As you see below, the blue area is the gust speed above the average. So a variable wind will show up graphically. The direction is shown in the title along with the average and gust relative to avg speeds. I particularly hate the weather applets that show the direction as an arrow, and wind speed as a smaller number. Chewing up screen for something I don't care about and not showing detailed wind observations.


As this was my first foray into KDE applets, I found the many tutorials on DataEngine and Applets to be a good start, but there are still times when you have to RTFS and grep the subversion to work out how to do things. I still have another plasmoid to write but a release will happen very soon. I infact tried kde-apps.org today but its interface is annoying so I'll likely shove it up on sf.net in the next few days.

Friday, April 23, 2010

Looking for some coding work...

If you are on the lookout for a C++, GTK+2, Qt, Linux developer with a PhD and experience in persistent storage and indexing then I'm looking for you!

For those who don't know me, I am "the libferris guy". Which means I have played with virtual filesystems for many many years and implemented a good handful of ways to index and search diverse filesystems. Some of the articles I did for Linux Journal and linux.com will give an impression of the sorts of things libferris can do, and in the next months the Linux Format includes information on Web services as a filesystem, eg, mounting flickr, youtube, and facebook.

After hacking RDF support into KOffice earlier this year, I would very much like to work more with Soprano and RDF technologies. But anything involving indexing and storage is also of huge interest. In fact one of the things I like about RDF at the low level is that it overlaps these desires too, for example, my custom model partial implementation for Soprano which is targeted at great performance on embedded devices.

I have implemented some GIST trees for PostgreSQL and worked with C++ and development on a Linux platform for over 10 years. If you are interested in these things or just want a Qt hacker for a while then please drop me a line using the nick for this blog at gmail or sourceforge as email address.

Thursday, April 8, 2010

Nepomuk & Social Networking: The Golden Opportunity

After reading an article on Boxee recently which described it's social network integration it occurred to me how wonderful this would be to have for KDE. Having tags and ratings on the desktop is a really nice thing, but having tags and ratings coming through for arbitrary pieces of information from your "friends" makes things quite interesting.

From the Boxee example, why can't I see that Fred has also scheduled to watch Program-X. At the moment such recommendations are handled by many folks through IM or email, which is quite kludgey to say the least. There is no simple click to record or accept a recommendation, you have to mentally context switch to the TV schedule and update.

One thing that makes this all come together is not thinking of tags or ratings as binary or a single 1-5 range. To quote my own code, if a tag is able to also record the thoughts of many actors as a range, say a double from 0-100, and each actor has a level of trust associated, then the system itself can infer that if Fred is watching something and it is rated SciFi then automatically I want to take a peek too. By allowing tags and ratings to capture more complexity behind the scenes, the computer can infer more for us, and part of that can be a traditional 1-5 rating or whatever... hey, I work on virtual filesystems, is it really that strange that I would want to virtualize file ratings too?

The big gain here is if KDE itself can provide the spine for this. In my own system I stopped short of being able to automatically distribute these tag and file ratings. Surely they can be sent to other libferris systems and integrated, but that process, and the one of tracking friends and assigning privileges to them is not 100%.

Combining RDF with the social network element is an interesting chance here IMHO. Perhaps a central server of sorts is only really needed for tracking the privileges and assigning friends, and a p2p protocol can then be used to actually transmit the RDF you have decided to share to your associates. Though a fully central server implementation would probably provide a quicker starting point. As an upside, this would allow syncing RDF between many of your own devices -- tags from the desktop appearing on mobile devices when the VPN is up.

Of course, information sharing would have to be explicitly condoned by the user, and public key crypto would be needed to ensure integrity, privacy, and authenticity etc.

This sort of thing extends nicely to audio and image apps like Amarok and KPA. If I give somebody a copy of some images I took of London, when I add tags, they should also trickle through the system to them. If they are looking at a photo of the Wigmore Hall I took, they might like to know more about that place, and perhaps which CDs I have of chamber music from that trip.

This is something I'd love to hack on when I get the chance. In the meantime I thought I'd drop the idea here in case there are other folks who are also interested and we can combine forces.