7/18/16

CONVERT LD2 TO TXT, CHUYỂN LINGOES DICTIONARY SANG MYSQL

FROM: https://nguyenduchanh.wordpress.com/2014/10/28/convert-ld2-to-txt-chuyen-lingoes-dictionary-sang-mysql/

Rảnh rỗi sinh nông nổi, đang tự làm cái project về từ điển cho riêng mình thì tình cờ tìm được một tools convert dữ liệu từ lingo sang txt muốn chia sẻ với mọi người.
link download:  https://github.com/windylea/lingoes-converter

Chuyển từ file lingo sang txt

Cách sử dụng lingoes-converter-master:
Đưa lên website của bạn hoặc chay localhost cũng được, url có cấu trúc
http://yourwebsite/lingoes-converter-master/converter.php?input=path/to/somefile.ld2&encodingWord=UTF-8&encodingDef=UTF-8
Giải thích một chút về các param:
input: đường dẫn tới file ld2 (file chứa dữ liệu về từ điển của lingo)
encodingWord: encoding của file nguồn
encodingDef: encoding của file đích
Lưu ý: lingoes lưu trữ dữ liệu dưới dạng: từ => miêu tả về từ dó
Do vậy khi convert sang file txt nên phân biệt hai phần này bằng một ký tự đặc biệt để dễ explode ra cho việc  insert vào mysql.
Ở đây mình dùng ký tự “|”. Có thể sửa lại ở file LingoesConverter.php dòng 493

Chuyển từ txt sang mysql

Ở đây mình lấy file English-Vietnamese.ld2 (file này có trong link download) làm ví dụ. Sau khi chạy đường dẫn http://yourwebsite/lingoes-converter-master/converter.php?input=English-Vietnamese.ld2&encodingWord=UTF-8&encodingDef=UTF-8 ta sẽ được file English-Vietnamese.txt ở dùng thư mục. File này  có khoảng 139205 dòng, rất lớn nên không thể insert chỉ bằng 1 câu lệnh sql
Việc tạo bảng và insert dữ liệu vào bảng đó mình sẽ không nói nữa vì mọi người quá quen việc này rồi. Ở đây mình chỉ hướng dẫn viết một đoạn mã đọc từng dòng (vài chục dòng) một để insert vào database cho đến hết file
Đoạn mã đó như sau:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
session_start();  // bên dưới sử dụng session nên phải khai báo cái này, để lưu lại thông tin đã chạy đến dòng nào rồi
$start = isset($_SESSION['start']) ? $_SESSION['start'] : 0; // bắt đầu từ 0 sau khi f5 lần 1 sẽ là 200, lần 2 là 400 ...
$num = 200; // đọc 200 dòng một lúc để insert vào database
for($i = $start; $i < ($start + $num); $i++){
    if($i >139205 ) { // for sẽ dừng khi đọc hết file
        echo "done";
    exit;
}
$file = "Vietnamese-English.txt";
$lines = file( $file );
$line = $lines[$i];
$line = explode("|",$line);
// insert to db
đoạn này các bạn tự viết
}
?>
"refresh" content="2" />
hehe
Bạn lưu file này vào thư mục vừa download về ví dụ tên file là a.php
sau đó bắt đầu chạy http://yourwebsite/lingoes-converter-master/a.php
Lưu ý: đoạn mã html bên dưới không có tác dụng gì ngoài việc f5 liên tục đường dẫnhttp://yourwebsite/lingoes-converter-master/a.php mỗi khi chạy xong. Thời gian delay là 2 giây
Thế là xong!

5/11/16

Sparklines Chart

  1. http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/sparkline/
  2. http://www.anychart.com/products/anychart/gallery/Sparklines/

Sparkline charts

JSparklines

JSparklines makes it straightforward to visualize numbers in Java tables by the use of sparklines. All that is needed is a couple of lines of code.
The charts are created using JFreeChart and added to the table columns using custom TableCellRenderers.
Supports more than 27 types of charts/renderers, including bar chart, line charts, stacked bar charts, bar charts with error bars, pie charts, scatter plots, interval charts, area charts, heat maps and box plots.

JSparklines Publication:


downloadv1.0.8 - All platformsReleaseNotesJavaDoc

How to use JSparklines

See the How to use JSparklines wiki page for code examples. JSparklines is also available as a Maven dependency.
If you have questions or would like to contribute to the JSparklines project, please contact the developers.

Examples

(Click on a figure to see the full size version)

Projects using JSparklines

PeptideShakerinterpretation of proteomics identification resultsVaudel et al: Nature Biotechnol. 2015 Jan;33(1):22-24.
DeNovoGUIde novo sequencing of tandem mass spectraMuth at al: J Proteome Res. 2014 Feb 7;13(2):1143-6.
SearchGUIgraphical user interface for proteomics identification search enginesVaudel et al: Proteomics 2011;11(5):996-9.
thermo-msf-parserparser and viewer for thermo msf filesColaert et al: J Proteome Res. 2011;10(8):3840-3.
Fragmentation Analyzeranalyzing MS/MS fragmentation dataBarsnes et al: Proteomics 2010;10(5):1087-90.
MetaProteomeAnalyzeranalyzing meta-proteomics dataMuth et al: J Proteome Res. 2015 Mar 6;14(3):1557-65.
proteocloudproteomics cloud computing pipelineMuth et al: J Proteomics. 2013 Jan 8. pii: S1874-3919(13)00013-4.
Are you using JSparklines and would like your project listed here? Contact the developers of JSparklines.

5/10/16

Database vs Data Warehouse: A Comparative Review

Ref: http://revistaie.ase.ro/content/43/11-velicanu.pdf


A question I often hear out in the field is: I already have a database, so why do I need a data warehouse for healthcare analytics? What is the difference between a database vs. a data warehouse? These questions are fair ones.
For years, I’ve worked with databases in healthcare and in other industries, so I’m very familiar with the technical ins and outs of this topic. In this post, I’ll do my best to introduce these technical concepts in a way that everyone can understand.
But, before we discuss the difference, could I ask one big favor? This will only take 10 seconds. Could you click below and take a quick poll? I’d like to find out if your organization has a data warehouse, data base(s), or if you don’t know? This would really help me better understand how prevalent data warehouses really are.
Before diving in to the topic, I want to quickly highlight the importance of analytics in healthcare. If you don’t understand the importance of analytics, discussing the distinction between a database and a data warehouse won’t be relevant to you. Here it is in a nutshell. The future of healthcare depends on our ability to use the massive amounts of data now available to drive better quality at a lower cost. If you can’t perform analytics to make sense of your data, you’ll have trouble improving quality and costs, and you won’t succeed in the new healthcare environment.

The High-level Distinction Between Databases and Data Warehouses

What I will refer to as a “database” in this post is one designed to make transactional systems run efficiently. Typically, this type of database is an OLTP (online transaction processing) database. An electronic health record (EHR) system is a great example of an application that runs on an OLTP database. In fact, an OLTP database is typically constrained to a single application.
Database vs. Data WarehouseThe important fact is that a transactional database doesn’t lend itself to analytics. To effectively perform analytics, you need a data warehouse. A data warehouse is a database of a different kind: an OLAP (online analytical processing) database. A data warehouse exists as a layer on top of another database or databases (usually OLTP databases). The data warehouse takes the data from all these databases and creates a layer optimized for and dedicated to analytics.
So the short answer to the question I posed above is this: A database designed to handle transactions isn’t designed to handle analytics. It isn’t structured to do analytics well. A data warehouse, on the other hand, is structured to make analytics fast and easy.
In healthcare today, there has been a lot of money and time spent on transactional systems like EHRs. The industry is now ready to pull the data out of all these systems and use it to drive quality and cost improvements. And that’s where a data warehouse comes into play.

Databases versus Data Warehouses: The Details

Now that you have the overall idea, I want to go into more detail about some of the main distinctions between a database and a data warehouse. Because I’m a visual person (and a database guy who likes rows and columns), I’ll compare and contrast the two in following table format:

Database vs. Data Warehouse

DatabaseData Warehouse
DefinitionAny collection of data organized for storage, accessibility, and retrieval.A type of database that integrates copies of transaction data from disparate source systems and provisions them for analytical use.
TypesThere are different types of databases, but the term usually applies to an OLTP application database, which we’ll focus on throughout this table.Other types of databases include OLAP (used for data warehouses), XML, CSV files, flat text, and even Excel spreadsheets. We’ve actually found that many healthcare organizations use Excel spreadsheets to perform analytics (a solution that is not scalable).A data warehouse is an OLAP database. An OLAP database layers on top of OLTPs or other databases to perform analytics.An important side note about this type of database: Not all OLAPs are created equal. They differ according to how the data is modeled. Most data warehouses employ either an enterprise or dimensional data model, but at Health Catalyst, we advocate a unique, adaptive Late- Binding™ approach. You can learn more about why theLate-Binding™ approach is so important in healthcare analytics in Late-Binding vs. Models: A Comparison of Healthcare Data Warehouse Methodologies.
SimilaritiesBoth OLTP and OLAP systems store and manage data in the form of tables, columns, indexes, keys, views, and data types. Both use SQL to query the data.
How usedTypically constrained to a single application: one application equals one database. An EHR is a prime example of a healthcare application that runs on an OLTP database. OLTP allows for quick real-time transactional processing. It is built for speed and to quickly record one targeted process (ex: patient admission date and time).Accommodates data storage for any number of applications: one data warehouse equals infinite applications and infinite databases.OLAP allows for one source of truth for an organization’s data. This source of truth is used to guide analysis and decision-making within an organization (ex: total patients over age 18 who have been readmitted, by department and by month). Interestingly enough, complex queries like the one just described are much more difficult to handle in an OLTP database.
Service Level Agreement (SLA)OLTP databases must typically meet 99.99% uptime. System failure can result in chaos and lawsuits. The database is directly linked to the front end application.Data is available in real time to serve the here-and-now needs of the organization. In healthcare, this data contributes to clinicians delivering precise, timely bedside care.With OLAP databases, SLAs are more flexible because occasional downtime for data loads is expected. The OLAP database is separated from frontend applications, which allows it to be scalable.Data is refreshed from source systems as needed (typically this refresh occurs every 24 hours). It serves historical trend analysis and business decisions.
OptimizationOptimized for performing read-write operations of single point transactions. An OLTP database should deliver sub-second response times.Performing large analytical queries on such a database is a bad practice, because it impacts the performance of the system for clinicians trying to use it for their day-to-day work. An analytical query could take several minutes to run, locking all clinicians out in the meantime.Optimized for efficiently reading/retrieving large data sets and for aggregating data. Because it works with such large data sets, an OLAP database is heavy on CPU and disk bandwidth.A data warehouse is designed to handle large analytical queries. This eliminates the performance strain that analytics would place on a transactional system.
Data OrganizationAn OLTP database structure features very complex tables and joins because the data is normalized (it is structured in such a way that no data is duplicated). Making data relational in this way is what delivers storage and processing efficiencies—and allows those sub-second response times.In an OLAP database structure, data is organized specifically to facilitate reporting and analysis, not for quick-hitting transactional needs. The data is denormalized to enhance analytical query response times and provide ease of use for business users. Fewer tables and a simpler structure result in easier reporting and analysis.
Reporting/AnalysisBecause of the number of table joins, performing analytical queries is very complex. They usually require the expertise of a developer or database administrator familiar with the application.Reporting is typically limited to more static, siloed needs. You can actually get quite a bit of reporting out of today’s EHRs (which run on an OLTP database), but these reports are static,one-time lists in PDF format. For example, you might generate a monthly report of heart failure readmissions or a list of all patients with a central line inserted. These reports are helpful— particularly for real-time reporting for bedside care—but they don’t allow in-depth analysis.With fewer table joins, analytical queries are much easier to perform. This means that semi-technical users (anyone who can write a basic SQL query) can fill their own needs.The possibilities for reporting and analysis are endless. When it comes to analyzing data, a static list is insufficient. There’s an intrinsic need for aggregating, summarizing, and drilling down into the data. A data warehouse enables you to perform many types of analysis:
  • Descriptive (what has happened)
  • Diagnostic (why it happened)
  • Predictive (what will happen)
  • Prescriptive (what to do about it)
This is the level of analytics required to drive real quality and cost improvement in healthcare.

I hope the information I’ve included here has helped you understand why data warehouses are so important to the future of healthcare. Improving quality and cost requires analytics. And analytics requires a data warehouse.
An OLTP database like that used by EHRs can’t handle the necessary level of analytics. My rule of thumb is this: If you get data into your EHR, you can report on it. If you get it into a data warehouse, you can analyze it.
It’s that simple.

4/20/16

Getting Started With ASP.NET 5 On Ubuntu 14.04.2 LTS

Getting Started With ASP.NET 5 On Ubuntu

 16. June 2015 22:59
Ever since the .NET stack went open source last year, there is a huge excitement among the developers about the .NET stuff and developing apps using .NET which are no longer limited to Windows platform. I tried to install ASP.NET VNext on Ubuntu VM in which I terribly failed in the first go. Why? because the tutorial I used was quite old and I messed up the installation of pre-requisites. But I get everything working in the second try. So here are the steps and commands that will get you started with ASP.NET VNext on Ubuntu.
I am setting up a fresh VM for development on Ubuntu 14.04.2 LTS
Installing Mono
First thing is to install Mono. For folks who are new to Linux environment, Mono is a community driven project which allows developers to build and run .NET application on Linux platforms. Here is the set of commands that I have to execute to install Mono.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update
Install the latest version of Mono available.
sudo apt-get install mono-complete
To check if Mono is successfully installed or to determine the version of Mono on you machine run the below command in the terminal.
mono --version
Installing LibUV
As stated on Github:
Libuv is a multi-platform asynchronous IO library that is used by the KestrelHttpServer that we will use to host our web applications.
Running the below command will install LibUV along with the dependencies require to build it.
sudo apt-get install automake libtool
Getting the source and building and installing it.
curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src
cd /usr/local/src/libuv-1.4.2
sudo sh autogen.sh
sudo ./configure
sudo make 
sudo make install
sudo rm -rf /usr/local/src/libuv-1.4.2 && cd ~/
sudo ldconfig
Here is a note at Githb repo that explains what the above set of commands are doing.
NOTE: make install puts libuv.so.1 in /usr/local/lib, in the above commands ldconfig is used to update ld.so.cache so that dlopen (see man dlopen) can load it. If you are getting libuv some other way or not running make install then you need to ensure that dlopen is capable of loading libuv.so.1
Getting .NET Version Manager (DNVM)
DNVM is a command line tool which allows you to get new build of the DNX (.NET Execution Environment) and allows you to switch between them. To get DNVM running fire the below command in the terminal.
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
To check if the DNVM is successfully installed on your machine, type DNVM in the terminal. The output should be something like this:
At any point of time if you want to list out the installed DNX runtimes, run the below command
dnvm list
The next step after this, is to upgrade the DNVM so you can use the dnx and dnu commands. Run the following command in the terminal
dnvm upgrade
Once this is done, we are all set to run ASP.NET VNext application on Ubuntu box. Clone the aspnet/Home repository from Github. If you don't have Git installed then install it with this simple command.
sudo apt-get install git
For simplicity, I have created a new directory on Ubuntu desktop named vnext. You can name the directory as you wish. Navigate to this directory in the terminal and clone the aspnet/Home repository.
git clone https://github.com/aspnet/Home.git
After cloning of repository is done, navigate to the 1.0.0-beta4 directory.
You can see three sample applications that you can test. For this tutorial I am going to checkout HelloMvc application. Get inside theHelloMvc directory and then, run the command 
dnu restore
This will take some time to execute. I didn't face this problem but there is a chance that someone will. When you run this command, theproject.json.lock file gets created and the restore of the package will start. In the end when the restore is finalizing, it may say permission is denied. To resolve this error you can change the permission of the folder by running the following command.
sudo chmod -R 755 HelloMvc
You should always change permission to 755 for directories and 644 for files.
After the execution is completed, you can start the server by running the command.
dnx . kestrel
This command will work for both web and mvc application. If you plan to test out the console application then you can run the following command.
dnx . run
The server runs at port 5004. Fire up the browser and type in http://localhost:5004/
Hope this is helpful for the first time users of Linux.

3/21/16

MSSQL - find a SubString in a field of tables AND find which tables have reference to this table

DECLARE
    @search_string  VARCHAR(100),
    @table_name     SYSNAME,
    @table_schema   SYSNAME,
    @column_name    SYSNAME,
    @sql_string     VARCHAR(2000)

SET @search_string = 'CCC Helpdesk'

DECLARE tables_cur CURSOR FOR SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'

OPEN tables_cur

FETCH NEXT FROM tables_cur INTO @table_schema, @table_name

WHILE (@@FETCH_STATUS = 0)
BEGIN
    DECLARE columns_cur CURSOR FOR SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @table_schema AND TABLE_NAME = @table_name AND COLLATION_NAME IS NOT NULL  -- Only strings have this and they always have it

    OPEN columns_cur

    FETCH NEXT FROM columns_cur INTO @column_name
    WHILE (@@FETCH_STATUS = 0)
    BEGIN
        SET @sql_string = 'IF EXISTS (SELECT * FROM ' + QUOTENAME(@table_schema) + '.' + QUOTENAME(@table_name) + ' WHERE ' + QUOTENAME(@column_name) + ' LIKE ''%' + @search_string + '%'') PRINT ''' + QUOTENAME(@table_schema) + '.' + QUOTENAME(@table_name) + ', ' + QUOTENAME(@column_name) + ''''

        EXECUTE(@sql_string)

        FETCH NEXT FROM columns_cur INTO @column_name
    END

    CLOSE columns_cur

    DEALLOCATE columns_cur

    FETCH NEXT FROM tables_cur INTO @table_schema, @table_name
END

CLOSE tables_cur

DEALLOCATE tables_cur

================================================================================================================================

SELECT
    fk.name 'FK Name',
    tp.name 'Parent table',
    cp.name, cp.column_id,
    tr.name 'Refrenced table',
    cr.name, cr.column_id
FROM
    sys.foreign_keys fk
INNER JOIN
    sys.tables tp ON fk.parent_object_id = tp.object_id
INNER JOIN
    sys.tables tr ON fk.referenced_object_id = tr.object_id
INNER JOIN
    sys.foreign_key_columns fkc ON fkc.constraint_object_id = fk.object_id
INNER JOIN
    sys.columns cp ON fkc.parent_column_id = cp.column_id AND fkc.parent_object_id = cp.object_id
INNER JOIN
    sys.columns cr ON fkc.referenced_column_id = cr.column_id AND fkc.referenced_object_id = cr.object_id
WHERE
tr.name = 'QueueDefinition'
ORDER BY
    tp.name, cp.column_id