Donnerstag, 27. August 2009

Kontochart erstellen mit Sparkassendaten

Kunden der Sparkasse können sich ihre Kontoauszüge auch im CSV Format herunterladen. Mit Hilfe von GNUplot und dieser Liste aller Kontobewegungen kann man dann natürlich ganz einfach nette Visualisierungen erstellen. Falls man mit Windows gestraft ist, kann man wenigstens noch Cygwin benutzen; das macht die ganze Arbeit wesentlich angenehmer.

Mein Problem war am Anfang, dass die Beträge jeweils die Differenz darstellen und nicht den Saldo zum jeweiligen Zeitpunkt. Wenn man das dann als Chart darstellt kommt natürlich nur Müll heraus. Ich habe ewig versucht das ganze mit GNUplot ausrechnen zu lassen; kam allerdings auf keinen grünen Zweig. Also schrieb ich schnell ein C++ Programm, welches die Daten auf die notwendige Art und Weise umschreibt. Hier ist es (uuencoded):

begin 644 main.cpp.gz
M'XL(`(!P;T4"`\U66V_:,!1^!HG_<$HE:D9&USU"J=1U[52I6JO>]A@9QRE6
M0XQB!]96_/<=WT*`3'N='Z"<F[_OW-Q#D;.L3#B<"JETP>G\K-,^K(0H$OG+
MEFC)F9;%EBAM\)Q*C'><\=^"T2QF5.GA;+%`DTZ[5!@3<CKG:D$9!Z63L9$S
MF2MM?HU&[E[X$5__O'MZC*^N;RY)MYPKRO4['S*U[/;'S0ZW3X\;CX*K,M.5
M?:>=9I)J>.'ZLBRD.E=7]C>IA>C!,RWZG?9'I]UJ*?'.8PW?.;N3(M<P,<IA
M*O*$'$5'+F2K960%7V3(A033"$XBZ`Z[P:;@NBQRL%D9C>II.;68SHBY%HW7
MQMZSV>!\<`+B\&\0>D-KA>B:POL2AOC&:8^5]?>\AH&72*&B`P<3<(%&HWPA
M5=]P<E[-S*/`W!.WMH$>RZA2\(TF#WPNF,QD?CZ7)=[RL;9.'J#!\Z!IH6_3
MRZ?[9YJ5',A>S7MP(W(>\N$\K1?R,AI/:VQIM1HUD7,8G/QW)KX,WK*A!GI6
MR%5#*HE/__$Q_.*0<YZ`GG'`/,+2)E+FV5L$2H)Z%0O`BX'F"1QUCS8U<[<.
MX&NH6Z>]E"*!52$TO[>C]2BO1%:KBBO(;:E3%$<&H#E.ZQ9'Z,<>N`B^<-+O
M$$B)]QZR&$6D;_.P[3L:V8@QPB@HRD&8-+IXPRE_$;FEWTI11<9&>U"I.::Y
M/X;!0&B;P!1.3^$3FN`7ZK(-5]/V<VIB.8AB`[&^E^HX-Q,9#BN+@N?:E-@@
M,C%K)T/QA2D7+Y#`%XO93GAU'LIYT&SGP/-QEZYFM@JX+TQ$DD:U:_O0ZR'=
MVE6&MUUONG@#^\?NW#1,'JF''->=+K%O)G6BOI>[H9?##MS:5M5.VW95Y=1D
MT_I%-O3GG2`N0::1)[N+G&Q%KCQ,#@<3X[(#!!5SJGEB"=8`[>Y=@H95M#K:
ML/OJ,M]_.#>.A'6"AM/LA)3_[M((N$+F.WQ1JED\I>QUOV1K\\&H9C,@^SNC
M[YN!R=*.0_=BQMDK4+>;90HJV"L0.>"K"E@)TUA=-^G&J=[2FY%J52_@YY,]
M)/[5FM(DKK]</9CN(IH.5S,L<_]?D=?5`^9S8EH51]3H][87V?JG(8QS%/:3
,6PA_`&0Q9^DH"0``
`
end


Also im Prinzip, muss man die Erste (unnötige) Zeile von umsaetze.csv löschen, da GNUplot damit nicht klar kommt. Dann, mein Programm (im selben Ordner) ausführen und schließlich GNUplot starten. Dort gibt man die folgenden Befehle ein:

set xdata time
set xlabel "Datum"
set ylabel "EUR"
set title "Kontochart Sparkasse"
set datafile separator ";"
set timefmt "%d.%m.%Y"
set terminal png size 1024,768
set output "Chart.png"


plot "result.csv" using 1:7 w boxes fs pattern 2


Und so könnte beispielsweise dann das Resultat aussehen (hier etwas verkleinert):



Oder man benutzt:

plot "result.csv" using 1:7 w l

und bekommt:



plot "result.csv" using 1:7 smooth bezier title "bezier" w l, \
     "result.csv" using 1:7 title "line" w lp


ist auch nicht schlecht.


Und weil GNUplot toll ist, geht das ganze auch noch mit candlesticks und financebars.

Dienstag, 25. August 2009

Howto compile libMSN without CMake

Well, this blog entry serves rather as a note to myself, but I guess it could be useful for others, too. Compiling the excellent libMSN is pretty easy (especially when running Linux), but every time I do something wrong with the cmake building system on Windows it becomes a PITA (I had some problems with cmake finding my OpenSSL installation... no idea why). That's why I'll show how to build it manually for Visual Studio 2008 (should also work with other versions though).

If you have already installed OpenSSL in your IDE, you can start immediately. If not, you can download here a precompiled package which contains everything you need (I used the package "Win32 OpenSSL v0.9.8k" with a size of 7MBs). Just put the 2 precompiled files and the headers into the particular directories of Visual Studio.

  1. At first, grab the latest version from SVN trunk: svn co https://libmsn.svn.sourceforge.net/svnroot/libmsn libmsn. In case you don't have a suitable SVN client: I'm quite happy for now with the free client from SlikSVN.
  2. Make a new empty file with the name config.h in trunk/msn. This file is normally automatically generated by cmake and contains a few macros which enable or disable certain features. But for now, we're in a hurry so we don't care :-).
  3. Now copy all header files in trunk/msn to a new msn folder in your include directory of visual studio (e.g.: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\msn).
  4. Create a new project with Visual Studio. We need an empty Win32 project for a dynamic link libary.
  5. Try to find "Add" -> "Existing Item" somewhere and add all headers and source files to the project. Add also all files in the subdirectory "libsiren".
  6. Open up your project settings (or property pages) :
  7. Go to "C/C++" -> "Preprocessor" and add msn_EXPORTS to the "Preprocessor Definitions".
  8. Go also to "General" and set the character set to "Not Set".
  9. Now "Linker" -> "Input" and add libeay32.lib and ssleay32.lib.
  10. You may experience some linker problems related to debug code. Search "Linker" -> "Debugging" and set "Generate Debug Info" to "No".
Now pray and compile the project. You should get libmsn.lib and libmsn.dll. Put the lib into the lib directory of Visual Studio and the DLL either into the same directory of your executable or into system32 of your windows folder. That's it.