Business Reports with L A TEX



Similar documents
50 TUGboat, Volume 31 (2010), No. 1. Plotting experimental data using pgfplots Joseph Wright

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

SQL SELECT Query: Intermediate

Oracle Application Express - Application Migration Workshop

UQC103S1 UFCE Systems Development. uqc103s/ufce PHP-mySQL 1

Joining Tables in Queries

Short notes on webpage programming languages

In-Depth Guide Advanced Database Concepts

Application note: Connecting the to a Database

Introduction to the Data Migration Framework (DMF) in Microsoft Dynamics WHITEPAPER

Online shopping store

Business Intelligence. 11. SSIS, ETL January 2014.

G563 Quantitative Paleontology. SQL databases. An introduction. Department of Geological Sciences Indiana University. (c) 2012, P.

Relational Databases for the Business Analyst

Modelling with R and MySQL. - Manual - Gesine Bökenkamp, Frauke Wiese, Clemens Wingenbach

Working with Data in ASP.NET 2.0 :: Creating Stored Procedures and User Defined Functions with Managed Code Introduction

Data processing goes big

Sisense. Product Highlights.

Graphing in L A TEX using PGF and TikZ

Visual FoxPro Accessing MySQL. presented to The Atlanta FoxPro Users Group June 19 th, 2007

Server side scripting and databases

INSTALLING, CONFIGURING, AND DEVELOPING WITH XAMPP

Using AND in a Query: Step 1: Open Query Design

Writing MySQL Scripts With Python's DB-API Interface

QWT Business Intelligence Project Plan

Python and MongoDB. Why?

Vendor: Crystal Decisions Product: Crystal Reports and Crystal Enterprise

Quick start. A project with SpagoBI 3.x

Project management integrated into Outlook

Report Builder. Microsoft SQL Server is great for storing departmental or company data. It is. A Quick Guide to. In association with

Installing the MySQL ODBC Connector Windows XP and Windows 7. Roth Technologies, LLC

Sharperlight 3.0 Sample Dashboard

BarTender Integration Methods. Integrating BarTender s Printing and Design Functionality with Your Custom Application WHITE PAPER

HTSQL is a comprehensive navigational query language for relational databases.

Information Server Documentation SIMATIC. Information Server V8.0 Update 1 Information Server Documentation. Introduction 1. Web application basics 2

Master Module SNET2 Seminar & Project Summer Term 2010

Architecting the Future of Big Data

Tips and Tricks SAGE ACCPAC INTELLIGENCE

Database Setup. Coding, Understanding, & Executing the SQL Database Creation Script

Create e-commerce website Opencart. Prepared by : Reth Chantharoth Facebook : rtharoth@yahoo.

The SkySQL Administration Console

SAP BusinessObjects Business Intelligence (BI) platform Document Version: 4.1, Support Package Report Conversion Tool Guide

EMC Documentum Content Services for SAP Document Controllers

FileMaker 14. ODBC and JDBC Guide

FileMaker 13. ODBC and JDBC Guide

FileMaker Pro and Microsoft Office Integration

Microsoft SQL Server is great for storing departmental or company data. It. A Quick Guide to Report Builder In association with

Seamless Web Data Entry for SAS Applications D.J. Penix, Pinnacle Solutions, Indianapolis, IN

Monitoring Oracle Enterprise Performance Management System Release Deployments from Oracle Enterprise Manager 12c

How To Install Amyshelf On Windows 2000 Or Later

Benchmarking and monitoring tools

José Carlos Ramalho

Setting Up ALERE with Client/Server Data

Using SAP Crystal Reports with SAP Sybase SQL Anywhere

Two new DB2 Web Query options expand Microsoft integration As printed in the September 2009 edition of the IBM Systems Magazine

Recurring Contract Billing Importer 2013

How To Contact The Author Introduction What You Will Need The Basic Report Adding the Parameter... 9

Backup and Restore MySQL Databases

May 20, MyCV * Author: Andrea Ghersi. Abstract

ECOMMERCE SITE LIKE- GRAINGER.COM

DiskPulse DISK CHANGE MONITOR

Gothenburg Mainframe and Continuous Integration. Jan Marek com. CA Technologies. Session S610

Session 15 OF, Unpacking the Actuary's Technical Toolkit. Moderator: Albert Jeffrey Moore, ASA, MAAA

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

PHP on IBM i: What s New with Zend Server 5 for IBM i

FileMaker 11. ODBC and JDBC Guide

Using Microsoft Access Front End to NIMSP MySQL Database

Build it with Drupal 8

Vendor: Brio Software Product: Brio Performance Suite

Security Development Tool for Microsoft Dynamics AX 2012 WHITEPAPER

Source Code Review Using Static Analysis Tools

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

Getting Started using the SQuirreL SQL Client

HELP DESK MANUAL INSTALLATION GUIDE

IP Application Security Manager and. VMware vcloud Air

DEVELOPMENT OF AN ANALYSIS AND REPORTING TOOL FOR ORACLE FORMS SOURCE CODES

HP Vertica Integration with SAP Business Objects: Tips and Techniques. HP Vertica Analytic Database

Installation Guide for contineo

Installation of IBM DB2 9.1.x and Q-Monitor 3.x.x

LATEX Document Management with Subversion

Title. Syntax. stata.com. odbc Load, write, or view data from ODBC sources. List ODBC sources to which Stata can connect odbc list

DIPLOMA IN WEBDEVELOPMENT

FileMaker 12. ODBC and JDBC Guide

Server side PDF generation based on L A TEX templates

Mercury Users Guide Version 1.3 February 14, 2006

SPEX for Windows Client Server Version 8.3. Pre-Requisite Document V th August 2006 SPEX CS 8.3

PowerPivot Microsoft s Answer to Self-Service Reporting

PDF MAKER FOR VTIGER CRM

Quick Connect Express for Active Directory

Connect to MySQL or Microsoft SQL Server using R

How To Backup A Database On A Microsoft Powerpoint 3.5 (Mysqldump) On A Pcode (Mysql) On Your Pcode On A Macbook Or Macbook (Powerpoint) On

Using the SQL Server Linked Server Capability

Novell ZENworks Asset Management 7.5

Database migration using Wizard, Studio and Commander. Based on migration from Oracle to PostgreSQL (Greenplum)

Generating Open For Business Reports with the BIRT RCP Designer

Transcription:

Business Reports with L A TEX Reporting, Controlling & Co. Uwe Ziegenhagen, Cologne ziegenhagen@gmail.com 9. Oktober 2012

Motivation My employer is a Private Equity fund manager in Cologne, belongs to Deutsche Bank Investor letters & reportings plus regulatory reporting (Bafin, SEC, etc.) Workflow: proprietary LoB 1 software + SQL Server Business Intelligence Layer Excel Word PDF Excel Word PDF requires huge amount of time Proof of Concept: How could a T EX-based workflow look alike? What can be automated? 1 Line of Business

My Setup Windows 7 64-bit with XAMPP (Apache, PHP, MySQL) phpmyadmin & HeidiSQL to work with MySQL Python 2.7 with MySQLDB 2, Eclipse with Pydev 3 MySQL ODBC Connector 64-bit to get data into Excel Excel2L A TEX 2.1 4 2 http://sourceforge.net/projects/mysql-python/ 3 http://pydev.org/ 4 http://www.ctan.org/tex-archive/support/excel2latex/

Sample Data Northwind Database, included in Access & SQL Server marakana.com/download/sql/northwind.sql for MySQL, set to UTF8 Tables Categories Customercustomerdemo Customerdemographics Customers Employees Employeeterritories Order_details Orders Products Region Shippers Suppliers Territories Usstates Some new tables and columns were added.

Desirable Reports & Documents Management Information Volume of Sales by customer and employee Sales growth Outstanding invoices Outstanding orders Lists of inventory Financial overviews Other useful information Generation of invoices General correspondence Premise: Keep the toolchain simple!

1st example: Generating a letter via SQL only UNION statement to mix separate SQL commands Number of columns must match 1 SELECT "\\documentclass{article}\r\n\\begin{document}" 2 UNION 3 SELECT "\\begin{itemize}" 4 UNION 5 SELECT Concat("\\item ",2 ReorderLevel, " Einheiten ", 6 productname, " ( Bestellnr. ", productid, ") zu je ", 7 unitcost, " Euro" ) 8 FROM products 9 WHERE discontinued = 0 10 AND unitsinstock < reorderlevel 11 AND unitsonorder = 0 12 UNION 13 SELECT "\\end{itemize}\r\n\\end{document}"

Result Conclusion In general it works, but not very good style! Mixing TEX and SQL may become a mess... Change of TEX-code requires change of the query

Next step: MySQL & Python Have MySQL deliver the data (only), have Python & L A TEX do the rest Rest means Request the data from MySQL Format the result Create the L ATEX file Control the compilation process Python (Wikipedia) general-purpose, interpreted design philosophy code readability syntax said to be clear and expressive large and comprehensive standard library

Python Minimal Database Example 1 import MySQLdb 2 mysql_opts = { 3 host : "localhost", user : "uwe", 4 pass : "xxxxxxxxx", db : "pydb" } 5 6 mysql = MySQLdb.connect(mysql_opts[ host ], 7 mysql_opts[ user ], mysql_opts[ pass ], 8 mysql_opts[ db ]) 9 10 cursor = mysql.cursor() 11 cursor.execute("select * FROM products ") 12 products = cursor.fetchall() 13 14 print products

Python Writing L A TEX code 1 headerfile = open("f:/header.tex","r") 2 header = headerfile.read() 3 footerfile = open("f:/footer.tex","r") 4 footer = footerfile.read() 5 6 f = open("f:/test.tex", "w") 7 f.write(header) 8 f.write("hallo \\LaTeX!\r\n"); 9 f.write(footer) 10 f.close() Compiling the source either with os.system( pdflatex filename.tex ) or use latexmk.py (http://pypi.python.org/pypi/latexmk.py/)

PythonTEX by Geoffrey Poore current version: 0.9beta3 from 17.07.2012 https://github.com/gpoore/pythontex various options for formatting the output supports scientific computing packages such as PyLab 5, SymPy 6 Installation Install Python (if not available on your machine) Download PythonTEX from https://github.com/gpoore/pythontex Run the installer script for TEX Live Use it! 5 http://www.scipy.org/pylab 6 http://code.google.com/p/sympy/

Python Writing L A TEX code 1 \documentclass{minimal} 2 \usepackage{pythontex} 3 \begin{document} 4 \begin{pyconsole}[][frame=single] 5 x = 123 6 y = 345 7 z = x + y 8 z 9 def f(expr): 10 return(expr**4) 11 12 f(x) 13 print( Python says hi from the console! ) 14 \end{pyconsole} 15 \end{document}

Workflow Run pdflatex on the TEX-code! Run pythontex2 / 3 on the TEX-code! Run pdflatex on the TEX-code again 7! pycode executed, but not typeset pyverb typeset, but not executed pyblock typeset and executed pyconsole interactive Python console 7 see appendix for TEXworks integration

Back to the first example... 1 \usepackage{pythontex} 2 \begin{document} 3 \begin{pycode }[][] 4 import MySQLdb as mdb 5 import sys 6 con = mdb.connect( localhost, read, bsvtufqwqadbk5na, northwind ); 7 with con: 8 cur = con.cursor() 9 cur. execute("select Concat(2 ReorderLevel, Einheiten,productname, ( Bestellnr., productid, ) zu je, round( unitcost,2), Euro ) FROM products WHERE discontinued = 0 AND unitsinstock < reorderlevel AND unitsonorder = 0") 10 11 rows = cur. fetchall () 12 f = open("test2.tex", "w") 13 for row in rows: 14 f. write ("\\item " + str(row[0])+"\r") 15 f. close () 16 \end{pycode} 17 18 \begin{itemize} 19 \input{./pythontex files orderlist2 /test2} 20 \end{itemize}

Result 30 Einheiten Nord-Ost Matjeshering (Bestellnr. 30) zu je 16.83 Euro 20 Einheiten Silberkarpfen (Bestellnr. 95) zu je 5.00 Euro 1

Another Example List of Open Payments OrderID Shipped on Total 11072 15.05.1998 5218.0 11008 06.05.1998 4903.5 11039 15.05.2000 3090.0 11068 16.08.1998 2384.8 11070 05.09.1998 1873.5 11059 15.07.1998 1838.0 11077 11.07.1998 1374.6 11045 08.08.1998 1309.5 11076 29.09.1998 1057.0 11058 12.08.1998 858.0

Graphics with pgfplots written by Christian Feuersänger, based on PGF & TikZ >400 pages documentation 1 \documentclass{standalone} 2 \usepackage{pgfplots} 3 \begin{document} 4 \begin{ tikzpicture } 5 \begin{axis }[ 6 symbolic x coords={kat 1,Kat 2,Kat 3}, 7 xtick =data] 8 \addplot[ybar, fill =blue] coordinates { 9 (Kat 1,10) 10 (Kat 2,5) 11 (Kat 3,8) 12 }; 13 \end{axis} 14 \end{ tikzpicture } 15 \end{document}

Result 10 8 6 Kat 1 Kat 2 Kat 3

Using PythonTEX with MySQL I 1 \documentclass{ scrartcl } 2 \usepackage{pythontex} 3 \usepackage[landscape,a4paper, left =1cm, 4 right =1cm,top=2.5cm,bottom=1cm]{geometry} 5 \usepackage{pgfplots} 6 \ pagestyle{empty} 7 8 \begin{document} 9 10 \begin{pycode }[][] 11 import MySQLdb as mdb 12 import sys 13 import os 14 15 con = mdb.connect( localhost, read, 16 bsvtufqwqadbk5na, northwind ); 17

Using PythonTEX with MySQL II 18 with con: 19 cur = con.cursor() 20 cur. execute("select e.firstname, \n\ 21 round(sum(det.unitprice det. quantity),2) as total,\n\ 22 o.employeeid\n\ 23 FROM order_details det\n\ 24 INNER JOIN orders o\n\ 25 ON o.orderid = det. orderid \n\ 26 inner join employees e\n\ 27 on e. EmployeeID = o.employeeid\n\ 28 group by o.employeeid\n\ 29 order by 3") 30 31 rows = cur. fetchall () 32 33 f = open("emps.dat", "w") 34 f. write("employee\t Revenue\t xpos\n") 35

Using PythonTEX with MySQL III 36 for row in rows: 37 f. write("" + str(row[0]) + "\t" + str(row[1]) + "\t" + str(row [2]) + "\n") 38 f. close () 39 \end{pycode} 40 41 \ centering 42 \begin{ tikzpicture } 43 \begin{axis }[ 44 ybar, xtick =data, ymin=0, xmax=9.5, 45 xticklabels from table={pythontex files empsrevenuepyt/emps.dat }{Employee}, 46 width=0.7\textwidth, 47 scaled y ticks = false, 48 yticklabel style ={/pgf/number format/fixed} 49 ] 50 51

Using PythonTEX with MySQL IV 52 \addplot table [ 53 x= xpos, 54 y=revenue, 55 width= 15cm 56 ] {pythontex files empsrevenuepyt/emps.dat}; 57 \end{axis} 58 \end{ tikzpicture } 59 \end{document}

Result 260,000 240,000 220,000 200,000 180,000 160,000 140,000 120,000 100,000 80,000 60,000 40,000 20,000 0 Nancy Andrew Janet Margaret Steven Michael Robert Laura Anne

Conclusion Mixing L A TEX + scripting language fairly easy PythonTEX combines TEX s power with Python s elegance Pgfplots is pretty powerful but needs some time to learn other interesting things: PGF pie charts (http://code.google.com/p/pgf-pie/) Excel + L ATEX Excel + Powershell + L ATEX To be continued...

TEXworks Integration following http://code.google.com/p/texworks/wiki/ AdvancedTypesettingTools Create a batch file pythonize.bat in the TEX live bin directory that contains (for Windows & Python 2.7): pdflatex -synctex=1 "%1"&& pythontex2 "%1"&& pdflatex -synctex=1 "%1" Create a new tool entry in the TEXworks settings