Initial import.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngine@57236 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Gianpaolo Coro 2012-08-23 12:15:24 +00:00
parent d34b63d317
commit dcd70c47e0
278 changed files with 0 additions and 32702 deletions

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EcologicalEngine</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -1,4 +0,0 @@
#Thu Jun 21 16:51:19 CEST 2012
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8

View File

@ -1,13 +0,0 @@
#Thu Jun 21 16:51:19 CEST 2012
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6

View File

@ -1,5 +0,0 @@
#Thu Jun 21 16:32:52 CEST 2012
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -1,2 +0,0 @@
v. 1.0.0 (20-04-2011)
* First release

173
build.xml
View File

@ -1,173 +0,0 @@
<?xml version="1.0"?>
<!-- Ant buildfile for Libraries
Version 0.1
INPUT PROPERTIES
This buildfile assumes that the following properties have or may have been defined in a "build.properties" file
in the configuration directory of the service (or else using the -D flag on the command line).
package: (mandatory) Root package of the service implementation: it should be the first package in the
implementation hierarchy which uniquely identifies the implementation.
lib.dir: (mandatory) directory with auxiliary dependencies.
etics.build: (optional) Set to 'true', it indicates that build structures and procedures
should be optimised for remote builds in ETICS. If it is omitted, this buildfile will optimise build structures and procedures
for local builds.
-->
<project default="deploy" name="Ecological Engine Buildfile">
<!-- environment -->
<property environment="env" />
<!-- external environment -->
<echo message="container.dir ->${env.GLOBUS_LOCATION}" level="info"/>
<property name="container.dir" value="${env.GLOBUS_LOCATION}" />
<!-- load non-standard tasks -->
<taskdef resource="ise/antelope/tasks/antlib.xml">
<classpath>
<pathelement location="${container.dir}/lib/AntelopeTasks_3.4.2.jar"/>
</classpath>
</taskdef>
<!-- discriminate between local and remote build -->
<property name="etics.build" value="false" />
<!-- library-specific locations -->
<property name="library.dir" location="." />
<property name="etc.dir.name" value="etc" />
<property name="etc.dir" value="${library.dir}/${etc.dir.name}" />
<property name="source.dir" value="${library.dir}/src" />
<!-- load input properties -->
<property file="${etc.dir}/build.properties" />
<stringutil property="package.dir" string="${package}"><!-- derive package.dir from ${package} -->
<replace regex="\." replacement="/"/>
</stringutil>
<!-- file defaults -->
<property name="jarfile" value="${package}.jar" />
<if name="etics.build" value="true">
<property name="build.location" location="${library.dir}" />
<property name="lib.location" value="${build.location}/lib" />
<else>
<property name="build.location" location="${env.BUILD_LOCATION}" />
<property name="lib.location" location="${build.location}/${lib.dir}" />
</else>
</if>
<!-- temporary build locations -->
<property name="build.dir" location="${build.location}/build" />
<property name="build.classes.dir" location="${build.dir}/classes" />
<property name="build.lib.dir" location="${build.dir}/lib" />
<!-- misc defaults -->
<property name="java.debug" value="on" />
<!-- initialisation tasks -->
<target name="init" depends="clean" description="creates build structures">
<!-- input summary -->
<echo message="Root Package -> ${package}" level="info"/>
<echo message="Configuration -> ${etc.dir}" level="info"/>
<echo message="External dependencies -> ${lib.location}" level="info"/>
<!-- output summary -->
<echo message="Library Jar -> ${jarfile}" level="info"/>
<!-- create temporary build folders -->
<mkdir dir="${build.dir}" />
<mkdir dir="${build.classes.dir}" />
<mkdir dir="${build.lib.dir}" />
<!-- create dependency location, if it does not exist already -->
<mkdir dir="${lib.location}" />
</target>
<target name="build" depends="init" description="build the library">
<javac srcdir="${source.dir}" destdir="${build.classes.dir}" debug="${java.debug}" deprecation="${java.deprecation}" description="Compile the library">
<include name="**/*.java" />
<classpath>
<fileset dir="${container.dir}/lib">
<include name="*.jar" />
<exclude name="${jarfile}" />
</fileset>
<fileset dir="${lib.location}">
<include name="**/*.jar" />
<exclude name="**/${jarfile}" />
</fileset>
</classpath>
</javac>
</target>
<target name="jar" depends="build" description="jar the library">
<copy toDir="${build.classes.dir}/META-INF">
<fileset dir="${etc.dir}" casesensitive="yes" />
</copy>
<copy todir="${build.classes.dir}">
<fileset dir="${source.dir}">
<include name="org/**/*.xsd"/>
<include name="org/**/*.xml"/>
<include name="org/**/*.properties"/>
</fileset>
</copy>
<jar jarfile="${build.lib.dir}/${jarfile}" basedir="${build.classes.dir}"/>
</target>
<target name="jar-dev" depends="build" description="jar the library including the source code">
<copy toDir="${build.classes.dir}/META-INF">
<fileset dir="${etc.dir}" casesensitive="yes" />
</copy>
<copy todir="${build.classes.dir}">
<fileset dir="${source.dir}">
<include name="org/**/*.java"/>
<include name="org/**/*.xsd"/>
<include name="org/**/*.xml"/>
<include name="org/**/*.properties"/>
</fileset>
</copy>
<jar jarfile="${build.lib.dir}/${jarfile}" basedir="${build.classes.dir}"/>
</target>
<target name="deploy" depends="jar" description="deploy the library">
<if name="etics.build" value="true">
<copy file="${build.lib.dir}/${jarfile}" toDir="${lib.location}"/>
<else>
<copy file="${build.lib.dir}/${jarfile}" toDir="${container.dir}/lib"/>
</else>
</if>
</target>
<target name="undeploy" description="undeploy the library jar">
<delete file="${container.dir}/lib/${jarfile}"/>
</target>
<target name="doc" description="Generate the library javadoc">
<javadoc access="public" author="true" sourcepath="${source.dir}" packagenames="${package}.*"
destdir="doc/api" nodeprecated="false" nodeprecatedlist="false"
noindex="false" nonavbar="false" notree="false"
source="1.6"
splitindex="true"
use="true" version="true" failonerror="false">
<classpath>
<fileset dir="${lib.location}">
<include name="**/*.jar" />
<exclude name="**/${jarfile}" />
</fileset>
<fileset dir="${container.dir}/lib">
<include name="*.jar" />
</fileset>
</classpath>
</javadoc>
</target>
<target name="clean">
<delete dir="${build.dir}" quiet="true"/>
</target>
</project>

View File

@ -1,32 +0,0 @@
#### Use two appenders, one to log to console, another to log to a file
log4j.rootCategory= R
#### First appender writes to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %p %t %c - %m%n
#log4j.appender.stdout.layout.ConversionPattern=%m%n
#log4j.appender.stdout.File=Analysis.log
#### Second appender writes to a file
log4j.logger.AnalysisLogger=trace,stdout, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
#log4j.appender.R=org.apache.log4j.AsyncAppender
#log4j.appender.R.Threshold=INFO
log4j.appender.R.File=Analysis.log
log4j.appender.R.MaxFileSize=50000KB
log4j.appender.R.MaxBackupIndex=2
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %p %t %c - %m%n
#log4j.appender.R.layout.ConversionPattern=%m%n
#### Third appender writes to a file
log4j.logger.org.hibernate=H
#log4j.appender.H=org.apache.log4j.RollingFileAppender
log4j.appender.H=org.apache.log4j.AsyncAppender
#log4j.appender.H.File=HibernateLog.log
#log4j.appender.H.MaxFileSize=1024KB
#log4j.appender.H.MaxBackupIndex=2
log4j.appender.H.layout=org.apache.log4j.PatternLayout
log4j.appender.H.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %p %t %c - %m%n

View File

@ -1,17 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="connection.url">jdbc:postgresql://localhost/testdb</property>
<property name="connection.username">gcube</property>
<property name="connection.password">d4science2</property>
<property name="dialect">org.hibernatespatial.postgis.PostgisDialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="c3p0.timeout">0</property>
<property name="c3p0.max_size">10</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">1</property>
<property name="current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>

View File

@ -1,13 +0,0 @@
AQUAMAPS_SUITABLE=org.gcube.dataanalysis.ecoengine.spatialdistributions.AquamapsSuitable
AQUAMAPS_NATIVE=org.gcube.dataanalysis.ecoengine.spatialdistributions.AquamapsNative
AQUAMAPS_NATIVE_2050=org.gcube.dataanalysis.ecoengine.spatialdistributions.AquamapsNative2050
AQUAMAPS_SUITABLE_2050=org.gcube.dataanalysis.ecoengine.spatialdistributions.AquamapsSuitable2050
REMOTE_AQUAMAPS_SUITABLE=org.gcube.dataanalysis.ecoengine.processing.RainyCloudGenerator
REMOTE_AQUAMAPS_NATIVE=org.gcube.dataanalysis.ecoengine.processing.RainyCloudGenerator
REMOTE_AQUAMAPS_NATIVE_2050=org.gcube.dataanalysis.ecoengine.processing.RainyCloudGenerator
REMOTE_AQUAMAPS_SUITABLE_2050=org.gcube.dataanalysis.ecoengine.processing.RainyCloudGenerator
DUMMY=org.gcube.dataanalysis.ecoengine.spatialdistributions.DummyAlgorithm
TEST=org.gcube.dataanalysis.ecoengine.spatialdistributions.TestAlgorithm
AQUAMAPS_NATIVE_NEURALNETWORK=org.gcube.dataanalysis.ecoengine.spatialdistributions.AquamapsNN
AQUAMAPS_SUITABLE_NEURALNETWORK=org.gcube.dataanalysis.ecoengine.spatialdistributions.AquamapsNNSuitable
AQUAMAPS_NEURAL_NETWORK_NS=org.gcube.dataanalysis.ecoengine.spatialdistributions.AquamapsNNNS

View File

@ -1,2 +0,0 @@
DISCREPANCY_ANALYSIS=org.gcube.dataanalysis.ecoengine.evaluation.DiscrepancyAnalysis
QUALITY_ANALYSIS=org.gcube.dataanalysis.ecoengine.evaluation.DistributionQualityAnalysis

View File

@ -1,2 +0,0 @@
LOCAL_WITH_DATABASE=org.gcube.dataanalysis.ecoengine.processing.LocalSplitGenerator
SIMPLE_LOCAL=org.gcube.dataanalysis.ecoengine.processing.LocalSimpleSplitGenerator

View File

@ -1 +0,0 @@
HSPEN_MODELER=org.gcube.dataanalysis.ecoengine.modeling.SimpleModeler

View File

@ -1,3 +0,0 @@
HSPEN=org.gcube.dataanalysis.ecoengine.models.ModelHSPEN
AQUAMAPSNN=org.gcube.dataanalysis.ecoengine.models.ModelAquamapsNN
AQUAMAPSNNNS=org.gcube.dataanalysis.ecoengine.models.ModelAquamapsNNNS

View File

@ -1 +0,0 @@
AQUAMAPS_SUITABLE=org.gcube.dataanalysis.peeng.models.AquamapsSuitableNode

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +0,0 @@
<ReleaseNotes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="xsd/changelog.xsd">
<Changeset component="org.gcube.content-management.ecological-engine.1-0-0"
date="2012-02-23">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

View File

@ -1,2 +0,0 @@
v. 1.0.0 (20-04-2011)
* First release

View File

@ -1 +0,0 @@
Used as a library in the gCube Framework

View File

@ -1,8 +0,0 @@
gCube System - License
------------------------------------------------------------
The gCube/gCore software is licensed as Free Open Source software conveying to
the EUPL (http://ec.europa.eu/idabc/eupl).
The software and documentation is provided by its authors/distributors "as is"
and no expressed or implied warranty is given for its use, quality or fitness
for a particular case.

View File

@ -1,2 +0,0 @@
Gianpaolo Coro (gianpaolo.coro@isti.cnr.it), CNR Pisa,
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"

View File

@ -1,42 +0,0 @@
The gCube System - Ecological Engine Library
------------------------------------------------------------
This work is partially funded by the European Commission in the
context of the D4Science project (www.d4science.eu), under the
1st call of FP7 IST priority.
Authors
-------
* Gianpaolo Coro (gianpaolo.coro@isti.cnr.it), CNR Pisa,
Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"
Version and Release Date
------------------------
version 1.2.0 (03-05-2012)
Description
--------------------
Support library for statistics analysis on Time Series data.
Download information
--------------------
Source code is available from SVN:
http://svn.research-infrastructures.eu/d4science/gcube/trunk/content-management/EcologicalModelling
Binaries can be downloaded from:
http://software.d4science.research-infrastructures.eu/
Documentation
-------------
VREManager documentation is available on-line from the Projects Documentation Wiki:
https://gcube.wiki.gcube-system.org/gcube/index.php/Ecological_Modeling
Licensing
---------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

View File

@ -1,7 +0,0 @@
<ReleaseNotes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="xsd/changelog.xsd">
<Changeset component="org.gcube.content-management.ecological-engine.1-0-0"
date="2012-02-23">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

View File

@ -1,42 +0,0 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>INSTALL</include>
<include>MAINTAINERS</include>
<include>changelog.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>${distroDirectory}/profile.xml</source>
<outputDirectory>/etc</outputDirectory>
<filtered>true</filtered>
</file>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
<file>
<source>${distroDirectory}/svnpath.txt</source>
<outputDirectory>/${artifactId}</outputDirectory>
<filtered>true</filtered>
</file>
</files>
</assembly>

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID></ID>
<Type>Library</Type>
<Profile>
<Description>Ecological Engine Library</Description>
<Class>EcologicalEngine</Class>
<Name>${artifactId}</Name>
<Version>1.2.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

View File

@ -1 +0,0 @@
https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngine

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jardesc>
<jar path="EcologicalEngineExecutor/AQUAMAPS_SUITABLE/ecologicalDataMining.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/EcologicalEngine/ecologicalEngine.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
<manifest generateManifest="true" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
<sealing sealJar="false">
<packagesToSeal/>
<packagesToUnSeal/>
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
<javaElement handleIdentifier="=EcologicalEngine/src\/main\/java"/>
</selectedElements>
</jardesc>

View File

@ -1,4 +0,0 @@
name = EcologicalEngine
package = org.gcube.dataanalysis.ecoengine
# Where the jar will be stored
lib.dir = Dependencies/org.gcube.dataanalysis.ecoengine.jar

View File

@ -1,156 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../xsd/service.xsd">
<ID />
<Type>Library</Type>
<Profile>
<Description>Ecological Engine Library</Description>
<Class>DataAnalysis</Class>
<Name>EcologicalEngine</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Description>Ecological Engine Library</Description>
<Name>EcologicalEngine</Name>
<Version>1.0.0</Version>
<Dependencies>
<Dependency>
<Service>
<Class>Common</Class>
<Name>hibernate-patched</Name>
<Version>3.5.2</Version>
</Service>
<Package>hibernate-patched</Package>
<Version>3.5.2</Version>
<Scope level="GHN"/>
<Optional>false</Optional>
</Dependency>
<Dependency>
<Service>
<Class>ExternalSoftware</Class>
<Name>postgresql-jdbc</Name>
<Version>8.04.00</Version>
</Service>
<Package>postgresql-jdbc</Package>
<Version>8.04.00</Version>
<Scope level="GHN" />
<Optional>false</Optional>
</Dependency>
<Dependency>
<Service>
<Class>ExternalSoftware</Class>
<Name>jaxen</Name>
<Version>1.1.0</Version>
</Service>
<Package>jaxen</Package>
<Version>1.1.0</Version>
<Scope level="GHN" />
<Optional>false</Optional>
</Dependency>
<Dependency>
<Service>
<Class>ExternalSoftware</Class>
<Name>jcommon</Name>
<Version>1.0.16</Version>
</Service>
<Package>jcommon</Package>
<Version>1.0.16</Version>
<Scope level="GHN" />
<Optional>false</Optional>
</Dependency>
<Dependency>
<Service>
<Class>Common</Class>
<Name>rapidminer-custom</Name>
<Version>1.0.0</Version>
</Service>
<Package>rapidminer-custom</Package>
<Version>1.0.0</Version>
<Scope level="GHN" />
<Optional>false</Optional>
</Dependency>
<Dependency>
<Service>
<Class>ExternalSoftware</Class>
<Name>hibernate-spatial-postgis</Name>
<Version>1.0.0</Version>
</Service>
<Package>hibernate-spatial-postgis</Package>
<Version>1.0.0</Version>
<Scope level="GHN" />
<Optional>false</Optional>
</Dependency>
<Dependency>
<Service>
<Class>ExternalSoftware</Class>
<Name>hibernate-spatial</Name>
<Version>1.0.0</Version>
</Service>
<Package>hibernate-spatial</Package>
<Version>1.0.0</Version>
<Scope level="GHN" />
<Optional>false</Optional>
</Dependency>
<Dependency>
<Service>
<Class>ExternalSoftware</Class>
<Name>postgis</Name>
<Version>2.0.0</Version>
</Service>
<Package>postgis</Package>
<Version>2.0.0</Version>
<Scope level="GHN" />
<Optional>false</Optional>
</Dependency>
<Dependency>
<Service>
<Class>ExternalSoftware</Class>
<Name>jts</Name>
<Version>1.10.0</Version>
</Service>
<Package>jts</Package>
<Version>1.10.0</Version>
<Scope level="GHN" />
<Optional>false</Optional>
</Dependency>
<Dependency>
<Service>
<Class>ExternalSoftware</Class>
<Name>slf4j</Name>
<Version>1.05.00</Version>
</Service>
<Package>slf4j</Package>
<Version>1.05.00</Version>
<Scope level="GHN"/>
<Optional>false</Optional>
</Dependency>
<Dependency>
<Service>
<Class>ExternalSoftware</Class>
<Name>google-gson</Name>
<Version>1.7.1</Version>
</Service>
<Package>google-gson</Package>
<Version>1.7.1</Version>
<Scope level="GHN"/>
<Optional>false</Optional>
</Dependency>
<Dependency>
<Service>
<Class>ExternalSoftware</Class>
<Name>jfreechart</Name>
<Version>1.0.13</Version>
</Service>
<Package>jfreechart</Package>
<Version>1.0.13</Version>
<Scope level="GHN"/>
<Optional>false</Optional>
</Dependency>
</Dependencies>
<Files>
<File>lib/org.gcube.dataanalysis.ecoengine.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

226
pom.xml
View File

@ -1,226 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
<relativePath />
</parent>
<groupId>org.gcube.dataanalysis</groupId>
<artifactId>ecological-engine</artifactId>
<version>1.3.0-SNAPSHOT</version>
<name>ecological-engine</name>
<description>ecological-engine library</description>
<properties>
<distroDirectory>${project.basedir}/distro</distroDirectory>
</properties>
<dependencies>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>graphlayout</groupId>
<artifactId>graphlayout</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.hibernatespatial</groupId>
<artifactId>hibernate-spatial-postgis</artifactId>
<version>1.0-M2</version>
</dependency>
<dependency>
<groupId>org.hibernatespatial</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>1.0-M2</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>hibernate-patched</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>jama</groupId>
<artifactId>jama</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>jfree</groupId>
<artifactId>jcommon</artifactId>
<version>1.0.16</version>
</dependency>
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht</artifactId>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-jdk1.6</artifactId>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.postgis</groupId>
<artifactId>postgis</artifactId>
<version>2.0.0SVN</version>
</dependency>
<dependency>
<groupId>org.postgis</groupId>
<artifactId>postgis-driver</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.4-702.jdbc4</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>rapidminer-custom</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3_min</artifactId>
<version>1.1.4c</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository Mirror</name>
<url>http://maven.research-infrastructures.eu/nexus/content/repositories/osgeo//</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,12 +0,0 @@
package org.gcube.contentmanagement.graphtools.abstracts;
import java.util.Map;
public interface GenericDBExtractor {
public SamplesTable getMonoDimTable (String table, String column);
public Map<String, SamplesTable> getMultiDimTemporalTables(String table, String xDimension, String groupDimension, String yValue, String speciesColumn, String... yFilters);
}

View File

@ -1,187 +0,0 @@
package org.gcube.contentmanagement.graphtools.abstracts;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import org.gcube.contentmanagement.graphtools.data.conversions.ImageTools;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
/*
* Converts a GraphData into a graphicable structure DataSet
* GenericStandaloneGraph: GraphData -> DataSet
*/
public abstract class GenericStandaloneGraph extends ApplicationFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
protected boolean big;
public GenericStandaloneGraph(String title) {
super(title);
big = false;
}
abstract protected Dataset generateDataset();
abstract protected JFreeChart createChart(Dataset dataset);
abstract protected GenericStandaloneGraph getInstance(String title);
public void render(Dataset set) {
render(-1, -1, set);
}
public void render(double x, double y, Dataset set) {
JFreeChart chart = createChart(set);
JPanel jp = new ChartPanel(chart);
this.setContentPane(jp);
this.pack();
if (big)
this.setBounds(0, 0, (int) this.getBounds().getWidth() * 2, (int) this.getBounds().getHeight() * 2);
if ((x == -1) || (y == -1))
RefineryUtilities.centerFrameOnScreen(this);
else
RefineryUtilities.positionFrameOnScreen(this, x, y);
this.setVisible(true);
}
public List<Image> renderGraphGroupImage(int width, int height, GraphGroups graphgroups) {
ArrayList<Image> images = new ArrayList<Image>();
Map<String, GraphData> graphmap = graphgroups.getGraphs();
double x = 0;
double y = 0;
double max = 1;
// int numberOfGraphs = graphmap.size();
for (String key : graphmap.keySet()) {
GenericStandaloneGraph graph = getInstance(key);
Dataset datas = graph.convert2Dataset(graphmap.get(key));
images.add(graph.renderImgObject(width, height, datas));
x += 0.1;
y += 0.1;
if (x > max || y > max) {
x = 0;
y = 0;
}
}
return images;
}
public void renderImages(String filePath, int width, int height, GraphGroups graphgroups) {
List<Image> images = renderGraphGroupImage(width,height,graphgroups);
int i=0;
for (Image img:images){
BufferedImage bimage = ImageTools.toBufferedImage(img);
File outputfile = new File(filePath+"_"+i+".png");
try{
ImageIO.write(bimage, "png", outputfile);
}catch(Exception e){
AnalysisLogger.getLogger().error("renderImages->Error in writing files ",e);
}
i++;
}
}
public Image renderImgObject(int width, int height, Dataset set) {
JFreeChart chart = createChart(set);
/*
JPanel jp = new ChartPanel(chart);
this.setContentPane(jp);
this.pack();
*/
// Image image = this.createImage(width, height);
Image image = ImageTools.toImage(chart.createBufferedImage(width, height));
return image;
}
public void renderGraphGroup(GraphGroups graphgroups) {
Map<String, GraphData> graphmap = graphgroups.getGraphs();
double x = 0;
double y = 0;
double max = 1;
// int numberOfGraphs = graphmap.size();
for (String key : graphmap.keySet()) {
GenericStandaloneGraph graph = getInstance(key);
Dataset datas = graph.convert2Dataset(graphmap.get(key));
graph.render(x, y, datas);
x += 0.1;
y += 0.1;
if (x > max || y > max) {
x = 0;
y = 0;
}
}
}
protected Dataset convert2Dataset(GraphData st) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
List<Point<? extends Number, ? extends Number>> pointslist = st.getData();
// NOTE: after the graph generation graphs are inverted in x and y
int numbOfRows = pointslist.size();
if (numbOfRows > 0) {
int numbOfCols = pointslist.get(0).getEntries().size();
for (int x = 0; x < numbOfRows; x++) {
String xlabel = pointslist.get(x).getLabel();
for (int y = 0; y < numbOfCols; y++) {
double value = pointslist.get(x).getEntries().get(y).getValue().doubleValue();
String ylabel = pointslist.get(x).getEntries().get(y).getLabel();
// System.out.println("ADDING : "+value+" , "+ylabel+" , "+xlabel);
dataset.addValue(value, xlabel, ylabel);
}
}
}
return dataset;
}
}

View File

@ -1,156 +0,0 @@
package org.gcube.contentmanagement.graphtools.abstracts;
import java.util.LinkedList;
import java.util.List;
import com.rapidminer.example.Attribute;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.example.table.AttributeFactory;
import com.rapidminer.example.table.DoubleArrayDataRow;
import com.rapidminer.example.table.MemoryExampleTable;
import com.rapidminer.tools.Ontology;
public abstract class SamplesTable {
// attributes = columns of numbers
public double minY = 0;
public double maxY = 0;
public double minX = 0;
public double maxX = 0;
public ExampleSet generateExampleSet() {
// create attribute list
List<Attribute> attributes = new LinkedList<Attribute>();
// generate columns for attributes
for (int a = 0; a < getNumOfAttributes(); a++) {
attributes.add(AttributeFactory.createAttribute("att" + a, Ontology.REAL));
}
// add a label column
Attribute label = AttributeFactory.createAttribute("label", Ontology.NOMINAL);
attributes.add(label);
// create table
MemoryExampleTable table = new MemoryExampleTable(attributes);
// fill table (here : only real values )
for (int d = 0; d < getNumOfDataRows(); d++) {
// generate a row of double values
double[] data = new double[attributes.size()];
// fill rows data
for (int a = 0; a < getNumOfAttributes(); a++) {
// all with proper data here
data[a] = getValue(d, a);
}
// maps the nominal classifcation to a double value
data[data.length - 1] = label.getMapping().mapString(getClassification(d));
// add data row
table.addDataRow(new DoubleArrayDataRow(data));
}
// create example set
ExampleSet exampleSet = table.createExampleSet(label);
return exampleSet;
}
public void generateSampleTable(ExampleSet es) {
MemoryExampleTable met = (MemoryExampleTable) es.getExampleTable();
int numofcolumns = met.getAttributeCount();
int numofrows = met.size();
// System.out.println("COL "+numofcolumns+" ROWS "+numofrows);
for (int i = 0; i < numofrows; i++) {
Attribute labelAtt = met.getAttribute(numofcolumns - 1);
int index = (int) met.getDataRow(i).get(labelAtt);
String label = labelAtt.getMapping().mapIndex(index);
addSampleRow(label, 0);
// addLabel(i,label);
for (int j = 0; j < numofcolumns - 1; j++) {
Attribute att = AttributeFactory.createAttribute("att" + j, Ontology.REAL);
att.setTableIndex(j);
// System.out.println("ADDING TO " + i+","+j);
DoubleArrayDataRow dadr = (DoubleArrayDataRow) met.getDataRow(i);
double element = dadr.get(att);
addSample(i, j, element);
}
}
}
abstract public int getNumOfAttributes();
abstract public int getNumOfDataRows();
abstract public double getValue(int d, int a);
abstract public String getClassification(int d);
public String toString() {
StringBuffer bs = new StringBuffer();
bs.append("NUMBER OF ROWS: " + getNumOfDataRows() + "\n");
bs.append("NUMBER OF COLUMNS: " + getNumOfAttributes() + "\n");
for (int i = 0; i < getNumOfDataRows(); i++) {
bs.append("ROW " + i + " : ");
bs.append("LABEL " + getClassification(i) + " : ");
for (int j = 0; j < getNumOfAttributes(); j++) {
bs.append(getValue(i, j) + "\t");
}
bs.append("\n");
}
return bs.toString();
}
public void calculateBounds() {
int Ylen = getNumOfAttributes();
int Xlen = getNumOfDataRows();
for (int i = 0; i < Xlen; i++) {
for (int j = 0; j < Ylen; j++) {
double localmin = minY;
double localmax = maxY;
if (j == 0) {
localmin = minX;
localmax = maxX;
}
double point = getValue(i, j);
if (point < localmin) {
localmin = point;
} else if (point > localmax) {
localmax = point;
}
if (j == 0) {
minX = localmin;
maxX = localmax;
} else {
minY = localmin;
maxY = localmax;
}
}
}
}
abstract public void addLabel(int i, String label);
abstract public void addSample(int i, int j, double value);
abstract public void addSampleRow(String label, double... values);
}

View File

@ -1,192 +0,0 @@
package org.gcube.contentmanagement.graphtools.core;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gcube.contentmanagement.graphtools.abstracts.SamplesTable;
import org.gcube.contentmanagement.graphtools.core.filters.Filter;
import org.gcube.contentmanagement.graphtools.data.GraphSamplesTable;
import org.gcube.contentmanagement.graphtools.data.conversions.GraphConverter2D;
import org.gcube.contentmanagement.graphtools.data.databases.CommonDBExtractor;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.contentmanagement.lexicalmatcher.utils.DatabaseFactory;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
import org.hibernate.SessionFactory;
import com.rapidminer.RapidMiner;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.preprocessing.sampling.AbsoluteSampling;
import com.rapidminer.tools.OperatorService;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class StatisticsGenerator {
public static void main(String[] args) throws Exception {
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
StatisticsGenerator stg = new StatisticsGenerator();
LexicalEngineConfiguration conf = new LexicalEngineConfiguration();
// database Parameters
conf.setDatabaseUserName("root");
// conf.setDatabasePassword("password");
conf.setDatabaseDriver("com.mysql.jdbc.Driver");
conf.setDatabaseURL("jdbc:mysql://localhost/timeseries");
conf.setDatabaseDialect("org.hibernate.dialect.MySQLDialect");
conf.setDatabaseAutomaticTestTable("connectiontesttable");
conf.setDatabaseIdleConnectionTestPeriod("3600");
// stg.init("./cfg/");
stg.init("./cfg/", conf);
stg.generateGraphs(3, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
}
SessionFactory referenceDBSession;
CommonDBExtractor extractor;
private static final String LogFile = "ALog.properties";
private static final String HibFile = "hibernate.cfg.xml";
private static final String OperatorsFile = "operators.xml";
private List<Filter> ColumnFilters;
private Filter XRangeFilter;
private Filter YRangeFilter;
private XStream xStream;
public void init(String cfgPath) throws Exception {
init(cfgPath, null);
}
public SessionFactory getDBSession() {
return this.referenceDBSession;
}
public void init(String cfgPath, LexicalEngineConfiguration config) throws Exception {
AnalysisLogger.setLogger(cfgPath + "/" + LogFile);
if (config == null)
referenceDBSession = DatabaseFactory.initDBConnection(cfgPath + HibFile);
else
referenceDBSession = DatabaseFactory.initDBConnection(cfgPath + HibFile, config);
ColumnFilters = new ArrayList<Filter>();
extractor = new CommonDBExtractor(referenceDBSession);
AnalysisLogger.getLogger().info("StatisticsGenerator->initialization complete");
System.setProperty("rapidminer.init.operators", cfgPath + OperatorsFile);
xStream = new XStream(new DomDriver());
RapidMiner.init();
}
public void resetFilters(){
ColumnFilters = new ArrayList<Filter>();
}
public void addColumnFilter(String column, String element, String operator) {
ColumnFilters.add(new Filter(column, element, operator));
}
public void addColumnFilter(String column, String element) {
ColumnFilters.add(new Filter(column, element));
}
public void addXRangeFilter(String xmin, String xmax) {
XRangeFilter = new Filter(xmin, xmax);
}
public void addYRangeFilter(String ymin, String ymax) {
YRangeFilter = new Filter(ymin, ymax);
}
public GraphGroups generateGraphs(int maxElements, String timeSeriesTable, String xDimension, String yDimension, String groupDimension, String speciesColumn, String... filters) throws Exception {
Map<String, SamplesTable> samplesMap = extractor.getMultiDimTemporalTables(ColumnFilters, YRangeFilter, timeSeriesTable, xDimension, groupDimension, yDimension, speciesColumn, filters);
AnalysisLogger.getLogger().info("StatisticsGenerator-> samplesMap has been generated");
AnalysisLogger.getLogger().trace(samplesMap.toString());
// setup Absolute Sampling operator
AbsoluteSampling asop = (AbsoluteSampling) OperatorService.createOperator("AbsoluteSampling");
asop.setParameter("sample_size", "" + maxElements);
asop.setParameter("local_random_seed", "-1");
// setup graphgroups
GraphGroups graphgroups = new GraphGroups();
int i = 1;
// for each samples table perform processing
for (String key : samplesMap.keySet()) {
// get samples table
SamplesTable stable = samplesMap.get(key);
// transform samples table into a list of points
List<Point<? extends Number, ? extends Number>> singlegraph = GraphConverter2D.transformTable(stable);
// filter XRange if necessary
if (XRangeFilter != null) {
singlegraph = GraphConverter2D.filterXRange(singlegraph, XRangeFilter.getFirstElement(), XRangeFilter.getSecondElement());
}
// setup the graph samples table to perform mining processing
GraphSamplesTable graphSamples = new GraphSamplesTable(singlegraph);
// if there are too many samples, perform downsampling
if (graphSamples.getNumOfDataRows() > maxElements) {
// generate an Example Set for Rapid Miner
ExampleSet es = graphSamples.generateExampleSet();
// apply Sampling
es = asop.apply(es);
// generate a new graph samples table
graphSamples = new GraphSamplesTable();
graphSamples.generateSampleTable(es);
// get the points list from the graph samples table
singlegraph = graphSamples.getGraph();
AnalysisLogger.getLogger().trace("Regeneration\n" + graphSamples.toString());
}
// reorder the elements of the points list
// this steps performs re-enumeration and reordering of the rows after the sampling operations
singlegraph = GraphConverter2D.reorder(singlegraph);
AnalysisLogger.getLogger().trace("Reordering\n" + singlegraph.toString());
if ((singlegraph != null)&&(singlegraph.size()>0)) {
// build up the GraphData for visualization
GraphData grd = new GraphData(singlegraph, true);
// calculate the bounds of the graph
graphSamples.calculateBounds();
// set the bounds
grd.setMaxY(graphSamples.maxY);
grd.setMinY(graphSamples.minY);
// add the points list
graphgroups.addGraph("Distribution for " + key, grd);
AnalysisLogger.getLogger().trace("StatisticsGenerator-> graphgroup " + i + " generated with key: " + key);
i++;
}
}
AnalysisLogger.getLogger().info("StatisticsGenerator-> graphgroups have been generated");
return graphgroups;
}
public String generateStringGraphs(int maxElements, String timeSeriesTable, String xDimension, String yDimension, String groupDimension, String speciesColumn, String... filters) throws Exception {
GraphGroups gg = generateGraphs(maxElements, timeSeriesTable, xDimension, yDimension, groupDimension, speciesColumn, filters);
return xStream.toXML(gg);
}
}

View File

@ -1,71 +0,0 @@
package org.gcube.contentmanagement.graphtools.core.filters;
public class Filter {
String firstElement;
String secondElement;
String operator;
public Filter(String first,String second, String operator){
setFirstElement(first);
setSecondElement(second);
setOperator(operator);
}
public Filter(String first,String second){
setFirstElement(first);
setSecondElement(second);
setOperator("=");
}
public void setFirstElement(String first){
firstElement = first;
}
public void setSecondElement(String second){
secondElement = second;
}
public void setOperator(String oper){
operator = oper;
}
public double getFirstNumber() {
double d = 0;
try {
d = Double.parseDouble(firstElement);
} catch (Exception e) {
}
return d;
}
public double getSecondNumber() {
double d = 0;
try {
d = Double.parseDouble(secondElement);
} catch (Exception e) {
}
return d;
}
public String getFirstElement() {
return firstElement;
}
public String getSecondElement() {
return secondElement;
}
public String toString(String logicoperator){
return logicoperator+" "+firstElement+operator+"'"+secondElement+"' ";
}
public String toString(){
return "or "+firstElement+operator+"'"+secondElement+"' ";
}
}

View File

@ -1,85 +0,0 @@
package org.gcube.contentmanagement.graphtools.data;
import java.util.HashMap;
import org.gcube.contentmanagement.graphtools.abstracts.SamplesTable;
public class BigSamplesTable extends SamplesTable {
BigSparseTable table;
HashMap<Integer, String> classifications;
Integer currentIndex;
public BigSamplesTable() {
table = new BigSparseTable();
classifications = new HashMap<Integer, String>();
currentIndex = 0;
}
@Override
public int getNumOfAttributes() {
return table.width().intValue();
}
@Override
public int getNumOfDataRows() {
return table.size().intValue();
}
@Override
public double getValue(int d, int a) {
return table.get(d, a);
}
@Override
public String getClassification(int d) {
return classifications.get(d);
}
public void addSampleRow(String label, double... values) {
classifications.put(currentIndex, label);
int j = 0;
for (Double value : values) {
table.add(currentIndex, j, value);
j++;
}
currentIndex = currentIndex + 1;
}
public void addSample(int i, int j, double value) {
if (i < currentIndex)
table.add(i, j, value);
}
public void addLabel(int i, String label) {
if (i < currentIndex)
classifications.put(i, label);
}
public static void main(String[] args){
BigSamplesTable bst = new BigSamplesTable();
bst.addSampleRow("prova 1", 10, 12,13,14,15);
bst.addSampleRow("prova 2", 20, 15,14,15);
bst.addSampleRow("prova 3", 30, 11,110,150);
bst.addSample(0, -1,150);
System.out.println(bst.toString());
bst.generateExampleSet();
}
}

View File

@ -1,82 +0,0 @@
package org.gcube.contentmanagement.graphtools.data;
import java.util.HashMap;
public class BigSparseTable {
HashMap<Integer, HashMap<Integer, Double>> table;
Integer tableSize;
Integer tableWidth;
public BigSparseTable() {
table = new HashMap<Integer, HashMap<Integer, Double>>();
tableSize = 0;
tableWidth = 0;
}
public Integer size() {
return tableSize;
}
public Integer width() {
return tableWidth;
}
public void add(Integer i, Integer j, double value) {
// System.out.println("ADDING " + i + "," + j);
if ((i<0)||(j<0))
return;
double val = get(i, j);
if (val != 0) {
table.get(i).put(j, value);
}
else {
HashMap<Integer, Double> row;
// if size<=i create a new hashmap
if (tableSize <= i) {
row = new HashMap<Integer, Double>();
table.put(i, row);
tableSize = i + 1;
}
// else get i-th hashmap
else {
row = table.get(i);
if (row == null) {
row = new HashMap<Integer, Double>();
table.put(i, row);
}
}
row.put(j, value);
if (tableWidth <= j)
tableWidth = j + 1;
}
}
// default is 0
public double get(Integer i, Integer j) {
Double value = null;
if (tableSize.compareTo(i) > 0) {
value = table.get(i).get(j);
}
if (value == null)
value = Double.valueOf(0);
return value;
}
}

View File

@ -1,178 +0,0 @@
package org.gcube.contentmanagement.graphtools.data;
import java.util.ArrayList;
import java.util.List;
import org.gcube.contentmanagement.graphtools.abstracts.SamplesTable;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
import org.gcube.portlets.user.timeseries.charts.support.types.ValueEntry;
/*
* Represents a graphicable SamplesTable to be converted into a GraphData
* Performs transformation from GraphData to SamplesTable
* GraphConverter2D : SamplesTable -> GraphData
* GraphSamplesTable: GraphData -> SamplesTable
*/
/*
*
* Structure of a transposed graph coming from common structure library
*
* Point 1 (Series1, DefaultValue1) -> (y1,xLabel1) (y2,xLabel2) (y3,xLabel3) ..
* Point 2 (Series2, DefaultValue2) -> (y1,xLabel1) (y2,xLabel2) (y3,xLabel3) ..
* ...
*
* Structure of a not-transposed graph coming from database
*
* Point 1 (xLabel1,EnumeratedValue1) -> (y1,Series1) (y2,Series2) (y3,Series3) ..
* Point 2 (xLabel2,EnumeratedValue2) -> (y1,Series1) (y2,Series2) (y3,Series3) ..
* ...
*/
public class GraphSamplesTable extends SamplesTable {
List<Point<? extends Number, ? extends Number>> singlegraph;
public GraphSamplesTable(List<Point<? extends Number, ? extends Number>> graph) {
super();
singlegraph = graph;
}
public GraphSamplesTable() {
super();
singlegraph = new ArrayList<Point<? extends Number, ? extends Number>>();
}
// builds up a graph from a set of values and lables
// used for building up graphs from simple data
public GraphSamplesTable(String seriesName, List<String> xLables, List<Double> yValues,boolean invert) {
super();
singlegraph = new ArrayList<Point<? extends Number, ? extends Number>>();
int size = xLables.size();
try {
if (invert){
Point p = new Point<Number, Number>(seriesName, Double.valueOf(0));
for (int i = 0; i < size; i++) {
ValueEntry v = new ValueEntry(xLables.get(i), yValues.get(i));
p.addEntry(v);
}
singlegraph.add(p);
}
else{
for (int i = 0; i < size; i++) {
Point p = new Point<Number, Number>(xLables.get(i),new Double(i));
ValueEntry v = new ValueEntry("series1", yValues.get(i));
p.addEntry(v);
singlegraph.add(p);
}
}
} catch (Exception e) {
}
}
@Override
public int getNumOfAttributes() {
if (singlegraph.size() > 0)
return singlegraph.get(0).getEntries().size() + 1;
else
return 0;
}
@Override
public int getNumOfDataRows() {
return singlegraph.size();
}
@Override
public double getValue(int d, int a) {
Double doub;
if (a == 0)
doub = (Double) singlegraph.get(d).getValue();
else
doub = (Double) singlegraph.get(d).getEntries().get(a - 1).getValue();
return doub.doubleValue();
}
@Override
public String getClassification(int d) {
StringBuffer sb = new StringBuffer();
int numbOfColumns = getNumOfAttributes();
sb.append(singlegraph.get(d).getLabel() + ";");
for (int i = 0; i < numbOfColumns - 1; i++) {
sb.append(singlegraph.get(d).getEntries().get(i).getLabel());
if (i < numbOfColumns - 2)
sb.append(";");
}
return sb.toString();
}
@Override
public void addLabel(int i, String label) {
singlegraph.get(i).setLabel(label);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void addSample(int i, int j, double value) {
try {
if (j == 0) {
Point p = singlegraph.get(i);
p.setValue(Double.valueOf(value));
} else {
Point<Double, Double> p = (Point<Double, Double>) singlegraph.get(i);
p.getEntries().get(j - 1).setValue(new Double(value));
}
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
@Override
public void addSampleRow(String label, double... values) {
try {
Double x = values[0];
Double y1 = Double.valueOf(0);
if (values.length > 1)
y1 = values[1];
String[] lables = label.split(";");
int labsize = lables.length;
String labelx = lables[0];
String labely1 = lables[1];
ValueEntry<Double> ve = new ValueEntry<Double>(labely1, y1);
Point<Double, Double> p = new Point<Double, Double>(labelx, x, ve);
for (int j = 2; j < labsize; j++) {
Double y = new Double(0);
if (values.length > j)
y = values[j];
p.getEntries().add(new ValueEntry<Double>(lables[j], y));
}
singlegraph.add(p);
} catch (Exception e) {
e.printStackTrace();
}
}
public List<Point<? extends Number, ? extends Number>> getGraph() {
return singlegraph;
}
}

View File

@ -1,410 +0,0 @@
package org.gcube.contentmanagement.graphtools.data.conversions;
import java.util.ArrayList;
import java.util.List;
import org.gcube.contentmanagement.graphtools.abstracts.SamplesTable;
import org.gcube.contentmanagement.graphtools.utils.MathFunctions;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
import org.gcube.portlets.user.timeseries.charts.support.types.ValueEntry;
/*
* Performs Operations on Lists of Points
* Helps in transforming a SamplesTable to a GraphData
*/
public class GraphConverter2D {
private static Point<? extends Number, ? extends Number> searchPoint(Point<? extends Number, ? extends Number> x, List<Point<? extends Number, ? extends Number>> samples) {
Point<? extends Number, ? extends Number> novelpoint = null;
for (Point<? extends Number, ? extends Number> point : samples) {
// if (point.getValue().equals(x.getValue())) {
if (point.getLabel().equals(x.getLabel())) {
novelpoint = point;
break;
}
}
return novelpoint;
}
// optimizes the dimensions of the sample table, ordering the x and y entries
@SuppressWarnings({ "rawtypes", "unchecked" })
public static List<Point<? extends Number, ? extends Number>> reduceDimension(List<Point<? extends Number, ? extends Number>> samples) {
ArrayList<Point<? extends Number, ? extends Number>> novelSamples = new ArrayList<Point<? extends Number, ? extends Number>>();
int novelCounter = 0;
try {
for (Point<? extends Number, ? extends Number> pointsample : samples) {
// search the current point in the new built list
Point<? extends Number, ? extends Number> novelPoint = searchPoint(pointsample, novelSamples);
int index = 0;
ValueEntry pointValue = null;
// if it is not the first insertion then find the optimal index for the y value of the current point
// that is: find the column to insert the value
if (novelCounter > 0) {
// find column index
pointValue = pointsample.getEntries().get(0);
List<?> referencevalues = novelSamples.get(0).getEntries();
int i = 0;
index = referencevalues.size();
// get the best column
for (Object val : referencevalues) {
if (((ValueEntry) val).getLabel().equals(pointValue.getLabel())) {
index = i;
break;
}
i++;
}
}
// if the point has not been inserted yet (there isn't another point with the same label previously inserted)
if (novelPoint == null) {
// generate a new y
ValueEntry ve = new ValueEntry(pointsample.getEntries().get(0).getLabel(), pointsample.getEntries().get(0).getValue());
// generate a new (x,y)
novelPoint = new Point(pointsample.getLabel(), pointsample.getValue());
// the number of columns to fill with 0s corresponds to all the columns
int numofcolumns = index;
if (novelCounter > 0)
numofcolumns = novelSamples.get(0).getEntries().size();
// fill all the columns with 0s
for (int j = 0; j < numofcolumns; j++) {
novelPoint.getEntries().add(j, new ValueEntry(novelSamples.get(0).getEntries().get(j).getLabel(), Double.valueOf(0)));
}
// add the y at the right column according to the calculated index
if (index >= novelPoint.getEntries().size())
novelPoint.getEntries().add(index, ve);
else
novelPoint.getEntries().set(index, ve);
// add the new point in the list
novelSamples.add(novelPoint);
novelCounter++;
} else {
// if we found a previous element update it
if (index >= novelPoint.getEntries().size())
// if the index is higher than the y size, add the column at the end
novelPoint.getEntries().add(index, pointValue);
else
// otherwise substitute the current index value
novelPoint.getEntries().set(index, pointValue);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return novelSamples;
}
// converts a bidimensional sampleTable to a list of bidimensional Points
@SuppressWarnings("unchecked")
public static List<Point<? extends Number, ? extends Number>> convert(SamplesTable sampleTable) {
ArrayList<Point<? extends Number, ? extends Number>> pointsList = new ArrayList<Point<? extends Number, ? extends Number>>();
try {
// every point has a label and a list of associated y points
int rows = sampleTable.getNumOfDataRows();
for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
// take the label: it is separated in two parts separated by ';'
String label = sampleTable.getClassification(rowIndex);
int commaIndex = label.indexOf(";");
String xlabel = label;
String ylabel = "";
if (commaIndex > 0) {
xlabel = label.substring(0, commaIndex);
ylabel = label.substring(commaIndex + 1);
}
double x = sampleTable.getValue(rowIndex, 0);
double y = sampleTable.getValue(rowIndex, 1);
ValueEntry<Double> ve = new ValueEntry<Double>(ylabel, y);
Point<Double, Double> p = new Point<Double, Double>(xlabel, x, ve);
pointsList.add(p);
}
} catch (Exception e) {
e.printStackTrace();
}
return pointsList;
}
@SuppressWarnings("rawtypes")
public static List<Point<? extends Number, ? extends Number>> deleteHeaders(List<Point<? extends Number, ? extends Number>> samples) {
int size = samples.size();
for (int i = 0; i < size; i++) {
Point p = samples.get(i);
if (p.getLabel().equals("header")) {
samples.remove(i);
size--;
i--;
}
}
return samples;
}
// performs a complete transformation
public static List<Point<? extends Number, ? extends Number>> transformTable(SamplesTable sampleTable) {
List<Point<? extends Number, ? extends Number>> singlegraph = convert(sampleTable);
singlegraph = reduceDimension(singlegraph);
singlegraph = deleteHeaders(singlegraph);
return singlegraph;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static List<Point<? extends Number, ? extends Number>> reorder(List<Point<? extends Number, ? extends Number>> samples) {
List<Point<? extends Number, ? extends Number>> orderedsamples = new ArrayList<Point<? extends Number, ? extends Number>>();
// check and reorder points
for (Point p : samples) {
int index = 0;
for (Point ordP : orderedsamples) {
if (ordP.getValue().doubleValue() > p.getValue().doubleValue()) {
break;
}
index++;
}
orderedsamples.add(index, p);
}
// re-enumerate x dimension
int i = 0;
for (Point ordP : orderedsamples) {
try {
ordP.setValue(Double.valueOf(i));
} catch (Exception e) {
}
i++;
}
return orderedsamples;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static List<Point<? extends Number, ? extends Number>> filterXRange(List<Point<? extends Number, ? extends Number>> samples, String minX, String maxX) {
List<Point<? extends Number, ? extends Number>> filteredsamples = new ArrayList<Point<? extends Number, ? extends Number>>();
boolean copy = false;
for (Point p : samples) {
if (p.getLabel().equals(minX)) {
copy = true;
}
if (copy) {
filteredsamples.add(p);
}
if (p.getLabel().equals(maxX)) {
break;
}
}
return filteredsamples;
}
public static final String SPIKE = "STATIONARY";
public static void anotateStationaryPoints(GraphGroups gg) {
for (String key : gg.getGraphs().keySet()) {
GraphData graph = gg.getGraphs().get(key);
// for each series
int trends = graph.getData().size();
int yvalues = graph.getData().get(0).getEntries().size();
// System.out.println("yvalues "+yvalues);
// System.out.println("trends "+trends);
for (int i = 0; i < trends; i++) {
double[] points = MathFunctions.points2Double(graph.getData(), i, yvalues);
double[] derivative = MathFunctions.derivative(points);
boolean[] spikes = MathFunctions.findSpikes(derivative, threshold);
for (int k = 0; k < yvalues; k++) {
if (spikes[k]) {
String label = graph.getData().get(i).getEntries().get(k).getLabel();
String newLabel = label + ";" + SPIKE;
graph.getData().get(i).getEntries().get(k).setLabel(newLabel);
}
}
}
}
// return gg;
}
private static double threshold = 0.001;
public static void anotateStationaryPoints(GraphGroups gg, List<String> lables) {
for (String key : gg.getGraphs().keySet()) {
GraphData graph = gg.getGraphs().get(key);
// for each series
int trends = graph.getData().size();
int yvalues = graph.getData().get(0).getEntries().size();
int spikeslablessize = lables.size();
// System.out.println("yvalues "+yvalues);
// System.out.println("trends "+trends);
for (int i = 0; i < trends; i++) {
double[] points = MathFunctions.points2Double(graph.getData(), i, yvalues);
double[] derivative = MathFunctions.derivative(points);
boolean[] spikes = MathFunctions.findSpikes(derivative, threshold);
int spikecounter = 0;
for (int k = 0; k < yvalues; k++) {
if (spikes[k]) {
String label = graph.getData().get(i).getEntries().get(k).getLabel();
String spikelable = SPIKE;
if (spikecounter < spikeslablessize)
spikelable = lables.get(spikecounter);
String newLabel = label + ";" + spikelable;
graph.getData().get(i).getEntries().get(k).setLabel(newLabel);
spikecounter++;
}
}
}
}
// return gg;
}
public static void anotatePoints(GraphGroups gg, List<Integer> pointsIndexes, List<String> lables) {
for (String key : gg.getGraphs().keySet()) {
GraphData graph = gg.getGraphs().get(key);
// for each series
int trends = graph.getData().size();
for (int i = 0; i < trends; i++) {
int progressive = 0;
for (Integer index : pointsIndexes) {
String label = graph.getData().get(i).getEntries().get(index.intValue()).getLabel();
String addinglabel = lables.get(progressive);
String newLabel = label;
if (addinglabel != null)
newLabel += ";" + addinglabel;
graph.getData().get(i).getEntries().get(index.intValue()).setLabel(newLabel);
progressive++;
}
}
}
// return gg;
}
// works a single trend in the graph
public static List<Point> getStationaryPoints(GraphData graph) throws Exception {
List<Point> st = new ArrayList<Point>();
Point p = graph.getData().get(0);
st.add(new Point(p.getLabel(), p.getValue()));
int yvalues = graph.getData().get(0).getEntries().size();
double[] points = MathFunctions.points2Double(graph.getData(), 0, yvalues);
double[] derivative = MathFunctions.derivative(points);
boolean[] spikes = MathFunctions.findSpikes(derivative, threshold);
for (int k = 0; k < yvalues; k++) {
if (spikes[k]) {
String label = graph.getData().get(0).getEntries().get(k).getLabel();
Double val = points[k];
ValueEntry v = new ValueEntry(label, val);
st.get(0).addEntry(v);
}
}
return st;
}
// works a single trend in the graph
public static List<String> getLablesFromPoints(Point points) throws Exception {
List<String> lables = new ArrayList<String>();
for (Object v : points.getEntries()) {
lables.add(((ValueEntry) v).getLabel());
}
return lables;
}
// works the first trend in the graph: takes a list of points according to a list of indexes
public static List<String> getLabelsfromIndexes(List<Point<? extends Number, ? extends Number>> points, List<Integer> indexes) throws Exception {
List<String> lables = new ArrayList<String>();
int size = indexes.size();
for (Integer index : indexes) {
Object v = points.get(0).getEntries().get(index);
lables.add(((ValueEntry) v).getLabel());
}
return lables;
}
// works the first trend in the graph: takes a list of points according to a list of indexes
public static void sampleAnotationBySameFollower(List<Point<? extends Number, ? extends Number>> samples) throws Exception {
String previousLabel = null;
// check and reorder points
for (Point p : samples) {
for (Object v : p.getEntries()) {
String label = ((ValueEntry) v).getLabel();
int indexcomma = label.indexOf(";");
if (indexcomma >= 0) {
String labelcountry = label.substring(indexcomma + 1);
// AnalysisLogger.getLogger().debug("sampleAnotationBySameFollower-> comparing "+labelcountry+" vs "+previousLabel+" ORIGINAL "+label);
if ((previousLabel != null) && (labelcountry.equals(previousLabel))) {
label = label.substring(0, indexcomma);
// AnalysisLogger.getLogger().debug("sampleAnotationBySameFollower-> ELIMINATING LABEL!!!");
((ValueEntry) v).setLabel(label);
} else
previousLabel = labelcountry;
}
}
}
}
// works the first trend in the graph: takes a list of points according to a list of indexes
public static void sampleAnotationByRange(List<Point<? extends Number, ? extends Number>> samples, int range) throws Exception {
if (range > 0) {
// check and reorder points
for (Point p : samples) {
int partialCounter = 0;
for (Object v : p.getEntries()) {
String label = ((ValueEntry) v).getLabel();
int indexcomma = label.indexOf(";");
if (indexcomma >= 0) {
//if not enough time has passed delete the label otherwise reset counter
if (partialCounter <= range) {
String labelcountry = label.substring(indexcomma + 1);
// AnalysisLogger.getLogger().debug("sampleAnotationByRange-> partial counter "+partialCounter+ " label "+ label);
label = label.substring(0, indexcomma);
// AnalysisLogger.getLogger().debug("sampleAnotationByRange-> ELIMINATING LABEL!!!");
((ValueEntry) v).setLabel(label);
}
else{
partialCounter = 0;
}
}
partialCounter++;
}
}
}
}
}

View File

@ -1,79 +0,0 @@
package org.gcube.contentmanagement.graphtools.data.conversions;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber;
import javax.swing.ImageIcon;
public class ImageTools {
public static Image toImage(BufferedImage bufferedImage) {
return Toolkit.getDefaultToolkit().createImage(bufferedImage.getSource());
}
public static BufferedImage toBufferedImage(Image image) {
if (image instanceof BufferedImage) {return (BufferedImage)image;}
// This code ensures that all the pixels in the image are loaded
image = new ImageIcon(image).getImage();
// Determine if the image has transparent pixels
boolean hasAlpha = hasAlpha(image);
// Create a buffered image with a format that's compatible with the screen
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
// Determine the type of transparency of the new buffered image
int transparency = Transparency.OPAQUE;
if (hasAlpha == true) {transparency = Transparency.BITMASK;}
// Create the buffered image
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
}
catch (HeadlessException e) {} //No screen
if (bimage == null) {
// Create a buffered image using the default color model
int type = BufferedImage.TYPE_INT_RGB;
if (hasAlpha == true) {type = BufferedImage.TYPE_INT_ARGB;}
bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
}
// Copy image to buffered image
Graphics g = bimage.createGraphics();
// Paint the image onto the buffered image
g.drawImage(image, 0, 0, null);
g.dispose();
return bimage;
}
public static boolean hasAlpha(Image image) {
// If buffered image, the color model is readily available
if (image instanceof BufferedImage) {return ((BufferedImage)image).getColorModel().hasAlpha();}
// Use a pixel grabber to retrieve the image's color model;
// grabbing a single pixel is usually sufficient
PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
try {pg.grabPixels();} catch (InterruptedException e) {}
// Get the image's color model
return pg.getColorModel().hasAlpha();
}
}

View File

@ -1,207 +0,0 @@
package org.gcube.contentmanagement.graphtools.data.databases;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.gcube.contentmanagement.graphtools.abstracts.GenericDBExtractor;
import org.gcube.contentmanagement.graphtools.abstracts.SamplesTable;
import org.gcube.contentmanagement.graphtools.core.filters.Filter;
import org.gcube.contentmanagement.graphtools.data.BigSamplesTable;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.DataTypeRecognizer;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.contentmanagement.lexicalmatcher.utils.DatabaseFactory;
import org.hibernate.SessionFactory;
public class CommonDBExtractor implements GenericDBExtractor {
SessionFactory dbSession;
public CommonDBExtractor(SessionFactory DbSession) {
dbSession = DbSession;
}
// produces a mono-dimensional table
public SamplesTable getMonoDimTable(String table, String column) {
BigSamplesTable monoSamples = new BigSamplesTable();
String query = "select distinct " + column + " from " + table + ";";
List<Object> resultSet = DatabaseFactory.executeSQLQuery(query, dbSession);
for (Object result : resultSet) {
try {
Double resultcount = (Double) result;
monoSamples.addSampleRow(column, resultcount);
} catch (Exception e) {
}
}
return monoSamples;
}
private String generateSelectionString(String... columns) {
String delimiter = " , ";
StringBuffer sb = new StringBuffer();
int numbOfColumns = columns.length;
for (int i = 0; i < numbOfColumns; i++) {
String column = columns[i];
sb.append(column);
if (i < numbOfColumns - 1)
sb.append(delimiter);
}
return sb.toString();
}
// SELECT field1,field5,field6,field3 FROM ts_161efa00_2c32_11df_b8b3_aa10916debe6 t where field3='Brown seaweeds';
private static final String staticQuery = "select distinct %1$s from %2$s where (%3$s) ";
private static final String staticOrderBy = " order by %1$s;";
private static final String descriptionQuery = "SELECT ordinal_position,column_name,data_type FROM information_schema.COLUMNS WHERE table_name ='%1$s'";
// produces a bi-dimensional table, where for a single x, multiple y are allowed
// transforms db column types to java types
private Map<String, String> getTypes(SessionFactory dbSession, String table) {
HashMap<String, String> typesMap = new HashMap<String, String>();
String queryDesc = String.format(descriptionQuery, table);
AnalysisLogger.getLogger().trace("Query for Description: " + queryDesc);
List<Object> resultSet = DatabaseFactory.executeSQLQuery(queryDesc, dbSession);
for (Object result : resultSet) {
Object[] resultArray = (Object[]) result;
String column_name = (String) resultArray[1];
String data_type = (String) resultArray[2];
typesMap.put(column_name, DataTypeRecognizer.transformTypeFromDB(data_type));
}
return typesMap;
}
private void updateSequence(SamplesTable sequence, Map<String, String> columnTypes, String xDimension, Object[] row, int index) {
// set correct x label and value
String xLabel = "";
Double xValue = Double.valueOf(0);
// String Type = columnTypes.get(xDimension);
// if it is a string set the label as the entry and the value as the index
// NOTE OLD CODE: the x axis is always meant to be in linear scale, for now
/*
* if (Type.equals(BigDecimal.class.getName())) { xLabel = "" + row[0]; xValue = Double.valueOf(index); } else {
*
* xLabel = xDimension; xValue = Double.valueOf("" + row[0]); }
*/
xLabel = "" + row[0];
xValue = Double.valueOf(index);
String label = xLabel + ";";
// record the y value by taking the row 3 as label and row 2 as the value
String yLabel = "";
Double yValue = Double.valueOf(0);
try {
yLabel += (String) row[3];
yValue = Double.valueOf("" + row[2]);
} catch (Exception e) {
}
label += yLabel;
sequence.addSampleRow(label, xValue, yValue);
}
// makes a query on the db and produces a HashMap of bi-dimensional tables including more parallel graphs
// each group represents a graph
// each graph has a xDimension and a label for each x (taken from x value)
// each x can have more than one y and label
// yValue is the column with y numeric values
// speciesColumn is the resulting column containing the labels for the ys
public Map<String, SamplesTable> getMultiDimTemporalTables(List<Filter> filters, Filter YRangeFilter, String table, String xDimension, String groupDimension, String yValue, String speciesColumn, String... yFilters) {
LinkedHashMap<String, SamplesTable> temporalSequence = new LinkedHashMap<String, SamplesTable>();
String selection = generateSelectionString(xDimension, groupDimension, yValue, speciesColumn);
StringBuffer whereclause = new StringBuffer();
int i = 0;
for (String columnFilter : yFilters) {
whereclause.append(speciesColumn + "='" + columnFilter + "'");
if (i < yFilters.length - 1)
whereclause.append(" or ");
i++;
}
String query = String.format(staticQuery, selection, table, whereclause);
if ((filters != null) && (filters.size() > 0)) {
query+="and (";
int kk =0;
for (Filter f : filters) {
// query += f.toString();
if (kk==0){
query += f.toString("");
}
else
query += f.toString("or");
kk++;
}
query+=")";
}
if (YRangeFilter != null) {
query += "and " + yValue + ">" + YRangeFilter.getFirstNumber() + " and " + yValue + "<" + YRangeFilter.getSecondNumber() + " ";
}
query += String.format(staticOrderBy, xDimension);
AnalysisLogger.getLogger().trace("Query: " + query);
List<Object> resultSet = DatabaseFactory.executeSQLQuery(query, dbSession);
// xdim, group, quantity, yLabel
Map<String, String> columnTypes = getTypes(dbSession, table);
if (resultSet != null) {
// for each result row
for (Object result : resultSet) {
// take the single row
Object[] resultArray = (Object[]) result;
// for each temporal dimension, generate a table
String temporalInfo = (String) resultArray[1];
// take the table for the temporal sequence
SamplesTable sequence = temporalSequence.get(temporalInfo);
// if table does not exist create a new table and add it to the sequence
if (sequence == null) {
sequence = new BigSamplesTable();
temporalSequence.put(temporalInfo, sequence);
// set fake elements as headers in order to understand the labels
for (String columnFilter : yFilters) {
sequence.addSampleRow("header;" + columnFilter, Double.NEGATIVE_INFINITY, 0);
}
}
// update the rows of the bidimensional table. Use as index the following: take the length of the sequence of values, then subtract the number of headers
updateSequence(sequence, columnTypes, xDimension, resultArray, sequence.getNumOfDataRows() - yFilters.length);
}
}
return temporalSequence;
}
public Map<String, SamplesTable> getMultiDimTemporalTables(String table, String xDimension, String groupDimension, String yValue, String speciesColumn, String... yFilters) {
return getMultiDimTemporalTables(null, null, table, xDimension, groupDimension, yValue, speciesColumn, yFilters);
}
}

View File

@ -1,35 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
public class ExampleExternalConfig {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
StatisticsGenerator stg = new StatisticsGenerator();
LexicalEngineConfiguration conf = new LexicalEngineConfiguration();
//database Parameters
conf.setDatabaseUserName("root");
// conf.setDatabasePassword("password");
conf.setDatabaseDriver("com.mysql.jdbc.Driver");
conf.setDatabaseURL("jdbc:mysql://localhost/timeseries");
conf.setDatabaseDialect("org.hibernate.dialect.MySQLDialect");
conf.setDatabaseAutomaticTestTable("connectiontesttable");
conf.setDatabaseIdleConnectionTestPeriod("3600");
stg.init("./cfg/",conf);
stg.generateGraphs(3, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
}
}

View File

@ -1,35 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
public class ExampleExternalConfigPostGress {
public static void main(String[] args) throws Exception{
String table = "ts_7ab1d700_18d9_11e0_b703_c9d7e969ced7";
String xDimension = "field3"; // the dates
String yDimension = "field5"; // values on Y
String groupDimension = "field2"; // group names
String speciesColumn = "field4"; // lines labels
String filter1 = "Perciformes";
String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
LexicalEngineConfiguration conf = new LexicalEngineConfiguration();
//database Parameters
conf.setDatabaseUserName("lucio");
conf.setDatabasePassword("d4science");
conf.setDatabaseDriver("org.postgresql.Driver");
conf.setDatabaseURL("jdbc:postgresql://dlib29.isti.cnr.it/timeseries");
conf.setDatabaseDialect("org.hibernate.dialect.PostgreSQLDialect");
conf.setDatabaseAutomaticTestTable("connectiontesttable");
conf.setDatabaseIdleConnectionTestPeriod("3600");
stg.init("./cfg/",conf);
stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
}
}

View File

@ -1,42 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
public class ExampleExternalConfigPostGressProd {
public static void main(String[] args) throws Exception{
String table = "ts_c4bdfaa0_6c16_11e0_bb1f_fb760af5afc7";
String xDimension = "field4"; // the dates
String yDimension = "field6"; // values on Y
String groupDimension = "field1"; // group names
String speciesColumn = "field2"; // lines labels
String filter1 = "ABW";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
AnalysisLogger.setLogger("./cfg/ALog.properties");
LexicalEngineConfiguration conf = new LexicalEngineConfiguration();
//database Parameters
conf.setDatabaseUserName("gcube1");
conf.setDatabasePassword("d4science");
conf.setDatabaseDriver("org.postgresql.Driver");
conf.setDatabaseURL("jdbc:postgresql://node28.p.d4science.research-infrastructures.eu/timeseries");
// conf.setDatabaseDialect("org.hibernate.dialect.MySQLDialect");
conf.setDatabaseDialect("org.hibernate.dialect.PostgreSQLDialect");
conf.setDatabaseAutomaticTestTable("connectiontesttable");
conf.setDatabaseIdleConnectionTestPeriod("3600");
stg.init("./cfg/",conf);
// stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn,filter1);
System.out.println();
}
}

View File

@ -1,51 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.HistogramGraph;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleFilters {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
StatisticsGenerator stg = new StatisticsGenerator();
LexicalEngineConfiguration conf = new LexicalEngineConfiguration();
//database Parameters
conf.setDatabaseUserName("root");
// conf.setDatabasePassword("password");
conf.setDatabaseDriver("com.mysql.jdbc.Driver");
conf.setDatabaseURL("jdbc:mysql://localhost/timeseries");
conf.setDatabaseDialect("org.hibernate.dialect.MySQLDialect");
conf.setDatabaseAutomaticTestTable("connectiontesttable");
conf.setDatabaseIdleConnectionTestPeriod("3600");
stg.init("./cfg/",conf);
// stg.addColumnFilter("field4", "F");
// stg.addColumnFilter("field5", "2005","<");
// stg.addXRangeFilter("2004", "2005");
// stg.addYRangeFilter("100", "300");
stg.addColumnFilter("field1", "Africa - Inland waters");
stg.addColumnFilter("field1", "Atlantic, Northeast");
GraphGroups gg = stg.generateGraphs(3, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
HistogramGraph series = new HistogramGraph("");
series.renderGraphGroup(gg);
}
}

View File

@ -1,52 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.HistogramGraph;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleFilters2 {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
StatisticsGenerator stg = new StatisticsGenerator();
LexicalEngineConfiguration conf = new LexicalEngineConfiguration();
//database Parameters
conf.setDatabaseUserName("root");
// conf.setDatabasePassword("password");
conf.setDatabaseDriver("com.mysql.jdbc.Driver");
conf.setDatabaseURL("jdbc:mysql://localhost/timeseries");
conf.setDatabaseDialect("org.hibernate.dialect.MySQLDialect");
conf.setDatabaseAutomaticTestTable("connectiontesttable");
conf.setDatabaseIdleConnectionTestPeriod("3600");
stg.init("./cfg/",conf);
// stg.addColumnFilter("field4", "F");
// stg.addColumnFilter("field5", "2005","<");
//stg.addXRangeFilter("2004", "2005");
stg.addYRangeFilter("5600000", "7000000");
/*
stg.addColumnFilter("field1", "Africa - Inland waters");
stg.addColumnFilter("field1", "Atlantic, Northeast");
*/
GraphGroups gg = stg.generateGraphs(3, table, xDimension, yDimension, groupDimension, speciesColumn, filter1);
HistogramGraph series = new HistogramGraph("");
series.renderGraphGroup(gg);
}
}

View File

@ -1,45 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples;
import java.util.List;
import java.util.Map;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.GaussianDistributionGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
import org.jfree.data.function.NormalDistributionFunction2D;
public class ExampleMeanVariance {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
Map<String,List<NormalDistributionFunction2D>> normalsmap = GaussianDistributionGraph.graphs2Normals(gg);
//show normals
for (String key:normalsmap.keySet()){
List<NormalDistributionFunction2D> normals = normalsmap.get(key);
System.out.println("Means and Variances for distribution named: "+key);
for (NormalDistributionFunction2D gaussian:normals){
System.out.print("("+gaussian.getMean()+" ; "+gaussian.getStandardDeviation()+") ");
}
System.out.println();
}
// AnalysisLogger.getLogger().debug("Generated! "+normalsmap);
}
}

View File

@ -1,42 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.RadarGraph;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExamplePostGressLocalRadar {
public static void main(String[] args) throws Exception{
AnalysisLogger.setLogger("./cfg/ALog.properties");
String table = "ts_3bdaf790_edbe_11e0_93e3_f6a9821baa29";
String xDimension = "field2"; // the dates
String yDimension = "field4"; // values on Y
String groupDimension = "field0"; // group names
String speciesColumn = "field3"; // lines labels
String filter2 = "Perciformes";
String filter1 = "Boregadus";
StatisticsGenerator stg = new StatisticsGenerator();
LexicalEngineConfiguration conf = new LexicalEngineConfiguration();
//database Parameters
conf.setDatabaseUserName("gcube");
conf.setDatabasePassword("d4science2");
conf.setDatabaseDriver("org.postgresql.Driver");
conf.setDatabaseURL("jdbc:postgresql://dbtest.next.research-infrastructures.eu/timeseries");
conf.setDatabaseDialect("org.hibernate.dialect.PostgreSQLDialect");
stg.init("./cfg/",conf);
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1);
RadarGraph radar = new RadarGraph("");
radar.renderGraphGroup(gg);
}
}

View File

@ -1,29 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.RadarGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleStaticConfig {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(3, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
RadarGraph radar = new RadarGraph("");
radar.renderGraphGroup(gg);
}
}

View File

@ -1,50 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.HistogramGraph;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class ExampleStringGraphData {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
StatisticsGenerator stg = new StatisticsGenerator();
LexicalEngineConfiguration conf = new LexicalEngineConfiguration();
//database Parameters
conf.setDatabaseUserName("root");
// conf.setDatabasePassword("password");
conf.setDatabaseDriver("com.mysql.jdbc.Driver");
conf.setDatabaseURL("jdbc:mysql://localhost/timeseries");
conf.setDatabaseDialect("org.hibernate.dialect.MySQLDialect");
conf.setDatabaseAutomaticTestTable("connectiontesttable");
conf.setDatabaseIdleConnectionTestPeriod("3600");
stg.init("./cfg/",conf);
//String generation
String ggs = stg.generateStringGraphs(100, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
System.out.println(ggs);
//String rebuilding
XStream xStream = new XStream(new DomDriver());
GraphGroups gg = (GraphGroups) xStream.fromXML(ggs);
//graph plot
HistogramGraph series = new HistogramGraph("");
series.renderGraphGroup(gg);
}
}

View File

@ -1,54 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import java.util.ArrayList;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.data.GraphSamplesTable;
import org.gcube.contentmanagement.graphtools.data.conversions.GraphConverter2D;
import org.gcube.contentmanagement.graphtools.plotting.graphs.TransectLineGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleDataBuiltGraph {
public static void main(String[] args) throws Exception{
ArrayList<String> l = new ArrayList<String>();
ArrayList<Double> v = new ArrayList<Double>();
ArrayList<String> stationaryLables = new ArrayList<String>();
for (int i=0;i<10;i++){
double d= 10*Math.random();
v.add(d);
l.add("value "+i);
if (d>5){
stationaryLables.add("statpoint"+i);
}
}
GraphSamplesTable gts = new GraphSamplesTable("Random Series",l,v,true);
GraphData grd = new GraphData(gts.getGraph(), false);
GraphGroups graphgroups = new GraphGroups();
graphgroups.addGraph("Distribution", grd);
GraphConverter2D.anotateStationaryPoints(graphgroups,stationaryLables);
GraphConverter2D.getStationaryPoints(grd);
TransectLineGraph series = new TransectLineGraph("");
series.renderGraphGroup(graphgroups);
// series.renderGraphGroup(gg);
}
}

View File

@ -1,65 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.data.conversions.GraphConverter2D;
import org.gcube.contentmanagement.graphtools.plotting.graphs.TransectLineGraph;
import org.gcube.contentmanagement.graphtools.utils.MathFunctions;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleDerivative {
public static void main(String[] args) throws Exception{
String table = "ts_a904da30_b4fc_11df_800d_bcef80d51986";
String xDimension = "field1";
String yDimension = "field4";
String groupDimension = "field2";
String speciesColumn = "field3";
String filter1 = "Toluene";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, speciesColumn, speciesColumn, filter1);
/*
for (String key:gg.getGraphs().keySet()){
GraphData graph = gg.getGraphs().get(key);
//for each series
int trends = graph.getData().size();
int yvalues = graph.getData().get(0).getEntries().size();
System.out.println("yvalues "+yvalues);
System.out.println("trends "+trends);
for (int i=0;i<trends;i++){
double [] points = MathFunctions.points2Double(graph.getData(), i, yvalues);
double [] derivative = MathFunctions.derivative(points);
boolean [] spikes = MathFunctions.findSpikes(derivative);
for (int k=0;k<yvalues;k++){
if (spikes[k]){
String label = graph.getData().get(i).getEntries().get(k).getLabel();
String newLabel = label+";spike";
graph.getData().get(i).getEntries().get(k).setLabel(newLabel);
}
}
}
}
*/
GraphConverter2D.anotateStationaryPoints(gg);
TransectLineGraph series = new TransectLineGraph("");
series.renderGraphGroup(gg);
// series.renderGraphGroup(gg);
}
}

View File

@ -1,29 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.HistogramGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleHistogram {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter2 = "Brown seaweeds";
String filter1 = "River eels";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
HistogramGraph series = new HistogramGraph("");
series.renderGraphGroup(gg);
}
}

View File

@ -1,113 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;
import javax.imageio.ImageIO;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.data.conversions.ImageTools;
import org.gcube.contentmanagement.graphtools.plotting.graphs.GaussianDistributionGraph;
import org.gcube.contentmanagement.graphtools.plotting.graphs.ScatterGraphGeneric;
import org.gcube.contentmanagement.graphtools.plotting.graphs.ScatterGraphNumeric;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class ExampleImage extends Applet {
public void paint1(Graphics g) {
BufferedImage bgimg = loadImage();
g.drawImage(bgimg, 0, 0, this);
// g.fillRect(0, 0, 10, 10);
}
static int width = 320;
static int height = 280;
private BufferedImage loadImage() {
String imgFileName = "C:/Users/coro/Desktop/WorkFolder/Workspace/StatisticsExtractor/weather-cloud.png";
BufferedImage img = null;
try {
img = ImageIO.read(new File(imgFileName));
} catch (Exception e) {
e.printStackTrace();
}
return img;
}
public void init() {
setBackground( Color.LIGHT_GRAY );
setSize(width, height);
}
// public void paint(Graphics g){
public static void main(String[] args){
try{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("C:/Users/coro/Desktop/WorkFolder/Workspace/StatisticsExtractor/cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1);
// ScatterGraphNumeric series = new ScatterGraphNumeric("");
// GaussianDistributionGraph series = new GaussianDistributionGraph("");
ScatterGraphGeneric series = new ScatterGraphGeneric("");
series.renderImages("./saved",width,height,gg);
AnalysisLogger.getLogger().debug("finished");
System.exit(0);
/* OLD CODE
List<Image> image = series.renderGraphGroupImage(width,height,gg);
Image singleimage = image.get(1);
BufferedImage bimage = ImageTools.toBufferedImage(singleimage);
XStream xStream = new XStream(new DomDriver());
String xmlimage = xStream.toXML(singleimage);
System.out.println(xmlimage);
File outputfile = new File("saved.png");
ImageIO.write(bimage, "png", outputfile);
*/
}catch(Exception e){
e.printStackTrace();
}
}
}

View File

@ -1,33 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.LineGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleLines {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
LineGraph series = new LineGraph("");
series.renderGraphGroup(gg);
}
}

View File

@ -1,32 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.GaussianDistributionGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleNormalDistribution {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter2 = "Brown seaweeds";
String filter1 = "River eels";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1);
GaussianDistributionGraph pie = new GaussianDistributionGraph("");
pie.renderGraphGroup(gg);
}
}

View File

@ -1,32 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.NumericSeriesGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleNumericSeries {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
NumericSeriesGraph series = new NumericSeriesGraph("");
series.renderGraphGroup(gg);
}
}

View File

@ -1,32 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.PieGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExamplePie {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
PieGraph pie = new PieGraph("");
pie.renderGraphGroup(gg);
}
}

View File

@ -1,32 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.RadarGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleRadar {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter2);
RadarGraph radar = new RadarGraph("");
radar.renderGraphGroup(gg);
}
}

View File

@ -1,30 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.ScatterGraphNumeric;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleScatter {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1);
// ScatterGraphGeneric series = new ScatterGraphGeneric("");
ScatterGraphNumeric series = new ScatterGraphNumeric("");
series.renderGraphGroup(gg);
}
}

View File

@ -1,32 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.TimeSeriesGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleTimeSeries {
public static void main(String[] args) throws Exception{
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1);
TimeSeriesGraph series = new TimeSeriesGraph("");
series.renderGraphGroup(gg);
}
}

View File

@ -1,32 +0,0 @@
package org.gcube.contentmanagement.graphtools.examples.graphsTypes;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.TimeSeriesGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleTimeSeries2 {
public static void main(String[] args) throws Exception{
String table = "ts_a904da30_b4fc_11df_800d_bcef80d51986";
String xDimension = "field1";
String yDimension = "field4";
String groupDimension = "field2";
String speciesColumn = "field3";
String filter1 = "Toluene";
String filter2 = "River eels";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1);
TimeSeriesGraph series = new TimeSeriesGraph("");
series.renderGraphGroup(gg);
}
}

View File

@ -1,143 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------------
* PieGraph.java
* ------------------
* (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.demo;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
/**
* A simple demonstration application showing how to create a pie chart using
* data from a {@link DefaultPieDataset}.
*/
public class PieChartDemo1 extends ApplicationFrame {
/**
* Default constructor.
*
* @param title the frame title.
*/
public PieChartDemo1(String title) {
super(title);
setContentPane(createDemoPanel());
}
/**
* Creates a sample dataset.
*
* @return A sample dataset.
*/
private static PieDataset createDataset() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("One", new Double(43.2));
dataset.setValue("Two", new Double(10.0));
dataset.setValue("Three", new Double(27.5));
dataset.setValue("Four", new Double(17.5));
dataset.setValue("Five", new Double(11.0));
dataset.setValue("Six", new Double(19.4));
return dataset;
}
/**
* Creates a chart.
*
* @param dataset the dataset.
*
* @return A chart.
*/
private static JFreeChart createChart(PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart(
"Pie Chart Demo 1", // chart title
dataset, // data
true, // include legend
true,
false
);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSectionOutlinesVisible(false);
plot.setNoDataMessage("No data available");
return chart;
}
/**
* Creates a panel for the demo (used by SuperDemo.java).
*
* @return A panel.
*/
public static JPanel createDemoPanel() {
JFreeChart chart = createChart(createDataset());
return new ChartPanel(chart);
}
/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {
// ******************************************************************
// More than 150 demo applications are included with the JFreeChart
// Developer Guide...for more information, see:
//
// > http://www.object-refinery.com/jfreechart/guide.html
//
// ******************************************************************
PieChartDemo1 demo = new PieChartDemo1("Pie Chart Demo 1");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}

View File

@ -1,143 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------------
* PieGraph.java
* ------------------
* (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.demo;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
/**
* A simple demonstration application showing how to create a pie chart using
* data from a {@link DefaultPieDataset}.
*/
public class SpiderWebDemo1 extends ApplicationFrame {
/**
* Default constructor.
*
* @param title the frame title.
*/
public SpiderWebDemo1(String title) {
super(title);
setContentPane(createDemoPanel());
}
/**
* Creates a sample dataset.
*
* @return A sample dataset.
*/
private static Dataset createDataset() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(35.0, "S1", "C1");
dataset.addValue(45.0, "S1", "C2");
dataset.addValue(55.0, "S1", "C3");
dataset.addValue(15.0, "S1", "C4");
dataset.addValue(25.0, "S1", "C5");
dataset.addValue(39.0, "S2", "C1");
dataset.addValue(20.0, "S2", "C2");
dataset.addValue(34.0, "S2", "C3");
dataset.addValue(30.0, "S2", "C4");
dataset.addValue(13.0, "S2", "C5");
return dataset;
}
/**
* Creates a chart.
*
* @param dataset the dataset.
*
* @return A chart.
*/
private static JFreeChart createChart(Dataset dataset) {
SpiderWebPlot plot = new SpiderWebPlot((DefaultCategoryDataset)dataset);
JFreeChart chart = new JFreeChart(plot);
return chart;
}
/**
* Creates a panel for the demo (used by SuperDemo.java).
*
* @return A panel.
*/
public static JPanel createDemoPanel() {
JFreeChart chart = createChart(createDataset());
JPanel jp = new ChartPanel(chart);
return jp;
}
/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {
// ******************************************************************
// More than 150 demo applications are included with the JFreeChart
// Developer Guide...for more information, see:
//
// > http://www.object-refinery.com/jfreechart/guide.html
//
// ******************************************************************
SpiderWebDemo1 demo = new SpiderWebDemo1("Web Chart Demo 1");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}

View File

@ -1,372 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* -----------------------
* SpiderWebPlotTests.java
* -----------------------
* (C) Copyright 2005-2008, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* Changes
* -------
* 10-Jun-2005 : Version 1 (DG);
* 01-Jun-2006 : Added testDrawWithNullInfo() method (DG);
* 05-Feb-2007 : Added more checks to testCloning (DG);
*
*/
package org.gcube.portlets.user.timeseriesportlets.rapidminer.plotting;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.text.DecimalFormat;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.chart.urls.StandardCategoryURLGenerator;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.util.Rotation;
import org.jfree.util.TableOrder;
/**
* Tests for the {@link SpiderWebPlot} class.
*/
public class SpiderWebPlotTests extends TestCase {
/**
* Returns the tests as a test suite.
*
* @return The test suite.
*/
public static Test suite() {
return new TestSuite(SpiderWebPlotTests.class);
}
/**
* Constructs a new set of tests.
*
* @param name the name of the tests.
*/
public SpiderWebPlotTests(String name) {
super(name);
}
/**
* Some checks for the equals() method.
*/
public void testEquals() {
SpiderWebPlot p1 = new SpiderWebPlot(new DefaultCategoryDataset());
SpiderWebPlot p2 = new SpiderWebPlot(new DefaultCategoryDataset());
assertTrue(p1.equals(p2));
assertTrue(p2.equals(p1));
// dataExtractOrder
p1.setDataExtractOrder(TableOrder.BY_COLUMN);
assertFalse(p1.equals(p2));
p2.setDataExtractOrder(TableOrder.BY_COLUMN);
assertTrue(p1.equals(p2));
// headPercent
p1.setHeadPercent(0.321);
assertFalse(p1.equals(p2));
p2.setHeadPercent(0.321);
assertTrue(p1.equals(p2));
// interiorGap
p1.setInteriorGap(0.123);
assertFalse(p1.equals(p2));
p2.setInteriorGap(0.123);
assertTrue(p1.equals(p2));
// startAngle
p1.setStartAngle(0.456);
assertFalse(p1.equals(p2));
p2.setStartAngle(0.456);
assertTrue(p1.equals(p2));
// direction
p1.setDirection(Rotation.ANTICLOCKWISE);
assertFalse(p1.equals(p2));
p2.setDirection(Rotation.ANTICLOCKWISE);
assertTrue(p1.equals(p2));
// maxValue
p1.setMaxValue(123.4);
assertFalse(p1.equals(p2));
p2.setMaxValue(123.4);
assertTrue(p1.equals(p2));
// legendItemShape
p1.setLegendItemShape(new Rectangle(1, 2, 3, 4));
assertFalse(p1.equals(p2));
p2.setLegendItemShape(new Rectangle(1, 2, 3, 4));
assertTrue(p1.equals(p2));
// seriesPaint
p1.setSeriesPaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.white));
assertFalse(p1.equals(p2));
p2.setSeriesPaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.white));
assertTrue(p1.equals(p2));
// seriesPaintList
p1.setSeriesPaint(1, new GradientPaint(1.0f, 2.0f, Color.yellow,
3.0f, 4.0f, Color.white));
assertFalse(p1.equals(p2));
p2.setSeriesPaint(1, new GradientPaint(1.0f, 2.0f, Color.yellow,
3.0f, 4.0f, Color.white));
assertTrue(p1.equals(p2));
// baseSeriesPaint
p1.setBaseSeriesPaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.black));
assertFalse(p1.equals(p2));
p2.setBaseSeriesPaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.black));
assertTrue(p1.equals(p2));
// seriesOutlinePaint
p1.setSeriesOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue,
3.0f, 4.0f, Color.black));
assertFalse(p1.equals(p2));
p2.setSeriesOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue,
3.0f, 4.0f, Color.black));
assertTrue(p1.equals(p2));
// seriesOutlinePaintList
p1.setSeriesOutlinePaint(1, new GradientPaint(1.0f, 2.0f, Color.blue,
3.0f, 4.0f, Color.green));
assertFalse(p1.equals(p2));
p2.setSeriesOutlinePaint(1, new GradientPaint(1.0f, 2.0f, Color.blue,
3.0f, 4.0f, Color.green));
assertTrue(p1.equals(p2));
// baseSeriesOutlinePaint
p1.setBaseSeriesOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.cyan,
3.0f, 4.0f, Color.green));
assertFalse(p1.equals(p2));
p2.setBaseSeriesOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.cyan,
3.0f, 4.0f, Color.green));
assertTrue(p1.equals(p2));
// seriesOutlineStroke
BasicStroke s = new BasicStroke(1.23f);
p1.setSeriesOutlineStroke(s);
assertFalse(p1.equals(p2));
p2.setSeriesOutlineStroke(s);
assertTrue(p1.equals(p2));
// seriesOutlineStrokeList
p1.setSeriesOutlineStroke(1, s);
assertFalse(p1.equals(p2));
p2.setSeriesOutlineStroke(1, s);
assertTrue(p1.equals(p2));
// baseSeriesOutlineStroke
p1.setBaseSeriesOutlineStroke(s);
assertFalse(p1.equals(p2));
p2.setBaseSeriesOutlineStroke(s);
assertTrue(p1.equals(p2));
// webFilled
p1.setWebFilled(false);
assertFalse(p1.equals(p2));
p2.setWebFilled(false);
assertTrue(p1.equals(p2));
// axisLabelGap
p1.setAxisLabelGap(0.11);
assertFalse(p1.equals(p2));
p2.setAxisLabelGap(0.11);
assertTrue(p1.equals(p2));
// labelFont
p1.setLabelFont(new Font("Serif", Font.PLAIN, 9));
assertFalse(p1.equals(p2));
p2.setLabelFont(new Font("Serif", Font.PLAIN, 9));
assertTrue(p1.equals(p2));
// labelPaint
p1.setLabelPaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.blue));
assertFalse(p1.equals(p2));
p2.setLabelPaint(new GradientPaint(1.0f, 2.0f, Color.red,
3.0f, 4.0f, Color.blue));
assertTrue(p1.equals(p2));
// labelGenerator
p1.setLabelGenerator(new StandardCategoryItemLabelGenerator("XYZ: {0}",
new DecimalFormat("0.000")));
assertFalse(p1.equals(p2));
p2.setLabelGenerator(new StandardCategoryItemLabelGenerator("XYZ: {0}",
new DecimalFormat("0.000")));
assertTrue(p1.equals(p2));
// toolTipGenerator
p1.setToolTipGenerator(new StandardCategoryToolTipGenerator());
assertFalse(p1.equals(p2));
p2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
assertTrue(p1.equals(p2));
// urlGenerator
p1.setURLGenerator(new StandardCategoryURLGenerator());
assertFalse(p1.equals(p2));
p2.setURLGenerator(new StandardCategoryURLGenerator());
assertTrue(p1.equals(p2));
// axisLinePaint
p1.setAxisLinePaint(Color.red);
assertFalse(p1.equals(p2));
p2.setAxisLinePaint(Color.red);
assertTrue(p1.equals(p2));
// axisLineStroke
p1.setAxisLineStroke(new BasicStroke(1.1f));
assertFalse(p1.equals(p2));
p2.setAxisLineStroke(new BasicStroke(1.1f));
assertTrue(p1.equals(p2));
}
/**
* Confirm that cloning works.
*/
public void testCloning() {
SpiderWebPlot p1 = new SpiderWebPlot(new DefaultCategoryDataset());
Rectangle2D legendShape = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
p1.setLegendItemShape(legendShape);
SpiderWebPlot p2 = null;
try {
p2 = (SpiderWebPlot) p1.clone();
}
catch (CloneNotSupportedException e) {
e.printStackTrace();
}
assertTrue(p1 != p2);
assertTrue(p1.getClass() == p2.getClass());
assertTrue(p1.equals(p2));
// change the legendItemShape
legendShape.setRect(4.0, 3.0, 2.0, 1.0);
assertFalse(p1.equals(p2));
p2.setLegendItemShape(legendShape);
assertTrue(p1.equals(p2));
// change a series paint
p1.setSeriesPaint(1, Color.black);
assertFalse(p1.equals(p2));
p2.setSeriesPaint(1, Color.black);
assertTrue(p1.equals(p2));
// change a series outline paint
p1.setSeriesOutlinePaint(0, Color.red);
assertFalse(p1.equals(p2));
p2.setSeriesOutlinePaint(0, Color.red);
assertTrue(p1.equals(p2));
// change a series outline stroke
p1.setSeriesOutlineStroke(0, new BasicStroke(1.1f));
assertFalse(p1.equals(p2));
p2.setSeriesOutlineStroke(0, new BasicStroke(1.1f));
assertTrue(p1.equals(p2));
}
/**
* Serialize an instance, restore it, and check for equality.
*/
public void testSerialization() {
SpiderWebPlot p1 = new SpiderWebPlot(new DefaultCategoryDataset());
SpiderWebPlot p2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(buffer);
out.writeObject(p1);
out.close();
ObjectInput in = new ObjectInputStream(
new ByteArrayInputStream(buffer.toByteArray()));
p2 = (SpiderWebPlot) in.readObject();
in.close();
}
catch (Exception e) {
e.printStackTrace();
}
assertEquals(p1, p2);
}
/**
* Draws the chart with a null info object to make sure that no exceptions
* are thrown.
*/
public void testDrawWithNullInfo() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(35.0, "S1", "C1");
dataset.addValue(45.0, "S1", "C2");
dataset.addValue(55.0, "S1", "C3");
dataset.addValue(15.0, "S1", "C4");
dataset.addValue(25.0, "S1", "C5");
SpiderWebPlot plot = new SpiderWebPlot(dataset);
JFreeChart chart = new JFreeChart(plot);
boolean success = false;
try {
BufferedImage image = new BufferedImage(200 , 100,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
// g2.dispose();
success = true;
}
catch (Exception e) {
success = false;
}
assertTrue(success);
}
}

View File

@ -1,43 +0,0 @@
package org.gcube.contentmanagement.graphtools.plotting.demo;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.data.category.DefaultCategoryDataset;
public class TestWeb {
/**
* @param args
*/
public static void main(String[] args) {
testDrawWithNullInfo();
}
public static void testDrawWithNullInfo() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(35.0, "S1", "C1");
dataset.addValue(45.0, "S1", "C2");
dataset.addValue(55.0, "S1", "C3");
dataset.addValue(15.0, "S1", "C4");
dataset.addValue(25.0, "S1", "C5");
SpiderWebPlot plot = new SpiderWebPlot(dataset);
JFreeChart chart = new JFreeChart(plot);
boolean success = false;
try {
BufferedImage image = new BufferedImage(200 , 100,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
// g2.dispose();
success = true;
}
catch (Exception e) {
success = false;
}
}
}

View File

@ -1,219 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2009, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* -------------------------
* TimeSeriesChartDemo1.java
* -------------------------
* (C) Copyright 2003-2009, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.demo;
import java.awt.Color;
import java.text.SimpleDateFormat;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.RefineryUtilities;
/**
* An example of a time series chart. For the most part, default settings are
* used, except that the renderer is modified to show filled shapes (as well as
* lines) at each data point.
*/
public class TimeSeriesChartDemo1 extends ApplicationFrame {
/**
* A demonstration application showing how to create a simple time series
* chart. This example uses monthly data.
*
* @param title the frame title.
*/
public TimeSeriesChartDemo1(String title) {
super(title);
ChartPanel chartPanel = (ChartPanel) createDemoPanel();
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}
/**
* Creates a chart.
*
* @param dataset a dataset.
*
* @return A chart.
*/
private static JFreeChart createChart(XYDataset dataset) {
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Legal & General Unit Trust Prices", // title
"Date", // x-axis label
"Price Per Unit", // y-axis label
dataset, // data
true, // create legend?
true, // generate tooltips?
false // generate URLs?
);
chart.setBackgroundPaint(Color.white);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
XYItemRenderer r = plot.getRenderer();
if (r instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
renderer.setDrawSeriesLineAsPath(true);
}
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
return chart;
}
/**
* Creates a dataset, consisting of two series of monthly data.
*
* @return The dataset.
*/
private static XYDataset createDataset() {
TimeSeries s1 = new TimeSeries("L&G European Index Trust");
s1.add(new Month(2, 2001), 181.8);
s1.add(new Month(3, 2001), 167.3);
s1.add(new Month(4, 2001), 153.8);
s1.add(new Month(5, 2001), 167.6);
s1.add(new Month(6, 2001), 158.8);
s1.add(new Month(7, 2001), 148.3);
s1.add(new Month(8, 2001), 153.9);
s1.add(new Month(9, 2001), 142.7);
s1.add(new Month(10, 2001), 123.2);
s1.add(new Month(11, 2001), 131.8);
s1.add(new Month(12, 2001), 139.6);
s1.add(new Month(1, 2002), 142.9);
s1.add(new Month(2, 2002), 138.7);
s1.add(new Month(3, 2002), 137.3);
s1.add(new Month(4, 2002), 143.9);
s1.add(new Month(5, 2002), 139.8);
s1.add(new Month(6, 2002), 137.0);
s1.add(new Month(7, 2002), 132.8);
TimeSeries s2 = new TimeSeries("L&G UK Index Trust");
s2.add(new Month(2, 2001), 129.6);
s2.add(new Month(3, 2001), 123.2);
s2.add(new Month(4, 2001), 117.2);
s2.add(new Month(5, 2001), 124.1);
s2.add(new Month(6, 2001), 122.6);
s2.add(new Month(7, 2001), 119.2);
s2.add(new Month(8, 2001), 116.5);
s2.add(new Month(9, 2001), 112.7);
s2.add(new Month(10, 2001), 101.5);
s2.add(new Month(11, 2001), 106.1);
s2.add(new Month(12, 2001), 110.3);
s2.add(new Month(1, 2002), 111.7);
s2.add(new Month(2, 2002), 111.0);
s2.add(new Month(3, 2002), 109.6);
s2.add(new Month(4, 2002), 113.2);
s2.add(new Month(5, 2002), 111.6);
s2.add(new Month(6, 2002), 108.8);
s2.add(new Month(7, 2002), 101.6);
// ******************************************************************
// More than 150 demo applications are included with the JFreeChart
// Developer Guide...for more information, see:
//
// > http://www.object-refinery.com/jfreechart/guide.html
//
// ******************************************************************
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);
dataset.addSeries(s2);
return dataset;
}
/**
* Creates a panel for the demo (used by SuperDemo.java).
*
* @return A panel.
*/
public static JPanel createDemoPanel() {
JFreeChart chart = createChart(createDataset());
ChartPanel panel = new ChartPanel(chart);
panel.setFillZoomRectangle(true);
panel.setMouseWheelEnabled(true);
return panel;
}
/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {
TimeSeriesChartDemo1 demo = new TimeSeriesChartDemo1(
"Time Series Chart Demo 1");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}

View File

@ -1,208 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------------
* PieGraph.java
* ------------------
* (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.graphs;
import java.awt.BasicStroke;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.contentmanagement.graphtools.abstracts.GenericStandaloneGraph;
import org.gcube.contentmanagement.graphtools.utils.MathFunctions;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.function.NormalDistributionFunction2D;
import org.jfree.data.general.Dataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.xy.XYSeriesCollection;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class GaussianDistributionGraph extends GenericStandaloneGraph {
private static final long serialVersionUID = 1L;
public GaussianDistributionGraph(String title) {
super(title);
}
protected Dataset generateDataset() {
XYSeriesCollection xyseriescollection = new XYSeriesCollection();
NormalDistributionFunction2D normaldistributionfunction2d = new NormalDistributionFunction2D(0.0D, 1.0D);
org.jfree.data.xy.XYSeries xyseries = DatasetUtilities.sampleFunction2DToSeries(normaldistributionfunction2d, -5.0999999999999996D, 5.0999999999999996D, 121, "N1");
xyseriescollection.addSeries(xyseries);
NormalDistributionFunction2D normaldistributionfunction2d1 = new NormalDistributionFunction2D(0.0D, Math.sqrt(0.20000000000000001D));
org.jfree.data.xy.XYSeries xyseries1 = DatasetUtilities.sampleFunction2DToSeries(normaldistributionfunction2d1, -5.0999999999999996D, 5.0999999999999996D, 121, "N2");
xyseriescollection.addSeries(xyseries1);
NormalDistributionFunction2D normaldistributionfunction2d2 = new NormalDistributionFunction2D(0.0D, Math.sqrt(5D));
org.jfree.data.xy.XYSeries xyseries2 = DatasetUtilities.sampleFunction2DToSeries(normaldistributionfunction2d2, -5.0999999999999996D, 5.0999999999999996D, 121, "N3");
xyseriescollection.addSeries(xyseries2);
NormalDistributionFunction2D normaldistributionfunction2d3 = new NormalDistributionFunction2D(-2D, Math.sqrt(0.5D));
org.jfree.data.xy.XYSeries xyseries3 = DatasetUtilities.sampleFunction2DToSeries(normaldistributionfunction2d3, -5.0999999999999996D, 5.0999999999999996D, 121, "N4");
xyseriescollection.addSeries(xyseries3);
return xyseriescollection;
}
protected JFreeChart createChart(Dataset dataset) {
String label = "mean:"+mean+" variance:"+variance;
if (label.length()>30)
label = label.substring(0,30)+"...";
JFreeChart jfreechart = ChartFactory.createXYLineChart("", label, "", (XYSeriesCollection)dataset, PlotOrientation.VERTICAL, true, true, false);
XYPlot xyplot = (XYPlot)jfreechart.getPlot();
xyplot.setDomainZeroBaselineVisible(true);
xyplot.setRangeZeroBaselineVisible(true);
xyplot.setDomainPannable(true);
xyplot.setRangePannable(true);
ValueAxis valueaxis = xyplot.getDomainAxis();
valueaxis.setLowerMargin(0.0D);
valueaxis.setUpperMargin(0.0D);
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyplot.getRenderer();
xylineandshaperenderer.setDrawSeriesLineAsPath(true);
xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(1.5F));
return jfreechart;
}
@Override
protected GenericStandaloneGraph getInstance(String title) {
return new GaussianDistributionGraph(title);
}
double mean;
double variance;
@Override
protected Dataset convert2Dataset(GraphData st) {
List<Point<? extends Number, ? extends Number>> pointslist = st.getData();
// NOTE: after the graph generation graphs are inverted in x and y
int numbOfSeries = pointslist.size();
XYSeriesCollection xyseriescollection = new XYSeriesCollection();
if (numbOfSeries > 0) {
int numbOfPoints = pointslist.get(0).getEntries().size();
//for each series
for (int s = 0; s < numbOfSeries; s++) {
//get label
String serieslabel = pointslist.get(s).getLabel();
double maxRange = st.getMaxY().doubleValue();
double minRange = st.getMinY().doubleValue();
//get doubles vector for performing mean and variance calculation
double [] points = MathFunctions.points2Double(pointslist,s,numbOfPoints);
mean = MathFunctions.mean(points);
variance = com.rapidminer.tools.math.MathFunctions.variance(points, Double.NEGATIVE_INFINITY);
mean = Math.round(mean);
variance = Math.round(variance);
if (variance==0)
variance = 0.1;
AnalysisLogger.getLogger().debug("mean "+mean+" variance "+variance);
//build up normal distribution and add to the series
NormalDistributionFunction2D normaldistributionfunction2d = new NormalDistributionFunction2D(mean, variance);
//make the representation a bit longer
maxRange = maxRange*2;
org.jfree.data.xy.XYSeries xyseries = DatasetUtilities.sampleFunction2DToSeries(normaldistributionfunction2d, minRange, maxRange, 121, serieslabel);
xyseriescollection.addSeries(xyseries);
}
}
return xyseriescollection;
}
public static Map<String,List<NormalDistributionFunction2D>> graphs2Normals(GraphGroups gg){
Map<String,List<NormalDistributionFunction2D>> normalsMap = new HashMap<String, List<NormalDistributionFunction2D>>();
for (String key:gg.getGraphs().keySet())
{
GraphData st = gg.getGraphs().get(key);
List<Point<? extends Number, ? extends Number>> pointslist = st.getData();
List<NormalDistributionFunction2D> normalsList = new ArrayList<NormalDistributionFunction2D>();
// NOTE: after the graph generation graphs are inverted in x and y
int numbOfSeries = pointslist.size();
if (numbOfSeries > 0) {
int numbOfPoints = pointslist.get(0).getEntries().size();
//for each series
for (int s = 0; s < numbOfSeries; s++) {
//get doubles vector for performing mean and variance calculation
double [] points = MathFunctions.points2Double(pointslist,s,numbOfPoints);
double mean = MathFunctions.mean(points);
double variance = com.rapidminer.tools.math.MathFunctions.variance(points, Double.NEGATIVE_INFINITY);
if (variance==0)
variance = 0.1;
AnalysisLogger.getLogger().debug("mean "+mean+" variance "+variance);
//build up normal distribution and add to the series
NormalDistributionFunction2D normaldistributionfunction2d = new NormalDistributionFunction2D(mean, variance);
normalsList.add(normaldistributionfunction2d);
}
}
normalsMap.put(key, normalsList);
}
return normalsMap;
}
}

View File

@ -1,131 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------------
* PieGraph.java
* ------------------
* (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.graphs;
import java.awt.Color;
import org.gcube.contentmanagement.graphtools.abstracts.GenericStandaloneGraph;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.LegendTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;
import org.jfree.ui.RectangleInsets;
public class HistogramGraph extends GenericStandaloneGraph {
private static final long serialVersionUID = 1L;
public HistogramGraph(String title) {
super(title);
}
protected Dataset generateDataset() {
String s = "S1";
String s1 = "S2";
String s2 = "S3";
String s3 = "Category 1";
String s4 = "Category 2";
String s5 = "Category 3";
String s6 = "Category 4";
String s7 = "Category 5";
String s8 = "Category 6";
String s9 = "Category 7";
String s10 = "Category 8";
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
defaultcategorydataset.addValue(1.0D, s, s3);
defaultcategorydataset.addValue(4D, s, s4);
defaultcategorydataset.addValue(3D, s, s5);
defaultcategorydataset.addValue(5D, s, s6);
defaultcategorydataset.addValue(5D, s, s7);
defaultcategorydataset.addValue(7D, s, s8);
defaultcategorydataset.addValue(7D, s, s9);
defaultcategorydataset.addValue(8D, s, s10);
defaultcategorydataset.addValue(5D, s1, s3);
defaultcategorydataset.addValue(7D, s1, s4);
defaultcategorydataset.addValue(6D, s1, s5);
defaultcategorydataset.addValue(8D, s1, s6);
defaultcategorydataset.addValue(4D, s1, s7);
defaultcategorydataset.addValue(4D, s1, s8);
defaultcategorydataset.addValue(2D, s1, s9);
defaultcategorydataset.addValue(1.0D, s1, s10);
defaultcategorydataset.addValue(4D, s2, s3);
defaultcategorydataset.addValue(3D, s2, s4);
defaultcategorydataset.addValue(2D, s2, s5);
defaultcategorydataset.addValue(3D, s2, s6);
defaultcategorydataset.addValue(6D, s2, s7);
defaultcategorydataset.addValue(3D, s2, s8);
defaultcategorydataset.addValue(4D, s2, s9);
defaultcategorydataset.addValue(3D, s2, s10);
return defaultcategorydataset;
}
protected JFreeChart createChart(Dataset dataset) {
JFreeChart chart = ChartFactory.createBarChart("Histogram Chart", "", "", (DefaultCategoryDataset) dataset, PlotOrientation.VERTICAL, true, true, false);
chart.setBackgroundPaint(Color.white);
CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
categoryplot.setBackgroundPaint(new Color(238, 238, 255));
categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
CategoryAxis categoryaxis = categoryplot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
LegendTitle legendtitle = new LegendTitle(categoryplot.getRenderer(0));
legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
return chart;
}
@Override
protected GenericStandaloneGraph getInstance(String title) {
return new HistogramGraph(title);
}
}

View File

@ -1,153 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------------
* PieGraph.java
* ------------------
* (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.graphs;
import java.awt.Color;
import org.gcube.contentmanagement.graphtools.abstracts.GenericStandaloneGraph;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;
public class LineGraph extends GenericStandaloneGraph {
private static final long serialVersionUID = 1L;
public LineGraph(String title) {
super(title);
}
protected Dataset generateDataset() {
// row keys...
String series1 = "First";
String series2 = "Second";
String series3 = "Third";
// column keys...
String type1 = "Type 1";
String type2 = "Type 2";
String type3 = "Type 3";
String type4 = "Type 4";
String type5 = "Type 5";
String type6 = "Type 6";
String type7 = "Type 7";
String type8 = "Type 8";
// create the dataset...
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0, series1, type1);
dataset.addValue(4.0, series1, type2);
dataset.addValue(3.0, series1, type3);
dataset.addValue(5.0, series1, type4);
dataset.addValue(5.0, series1, type5);
dataset.addValue(7.0, series1, type6);
dataset.addValue(7.0, series1, type7);
dataset.addValue(8.0, series1, type8);
dataset.addValue(5.0, series2, type1);
dataset.addValue(7.0, series2, type2);
dataset.addValue(6.0, series2, type3);
dataset.addValue(8.0, series2, type4);
dataset.addValue(4.0, series2, type5);
dataset.addValue(4.0, series2, type6);
dataset.addValue(2.0, series2, type7);
dataset.addValue(1.0, series2, type8);
dataset.addValue(4.0, series3, type1);
dataset.addValue(3.0, series3, type2);
dataset.addValue(2.0, series3, type3);
dataset.addValue(3.0, series3, type4);
dataset.addValue(6.0, series3, type5);
dataset.addValue(3.0, series3, type6);
dataset.addValue(4.0, series3, type7);
dataset.addValue(3.0, series3, type8);
return dataset;
}
protected JFreeChart createChart(Dataset dataset) {
// create the chart...
JFreeChart chart = ChartFactory.createLineChart(
this.getTitle(), // chart title
"", // domain axis label
"", // range axis label
(DefaultCategoryDataset)dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.white);
CategoryPlot plot = chart.getCategoryPlot();
// plot.setBackgroundPaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setDomainCrosshairVisible(true);
plot.setDomainGridlinesVisible(true);
plot.setRangeCrosshairVisible(true);
plot.setRenderer(new LineAndShapeRenderer(true,true));
//deprecated
/*
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setShapesVisible(true);
renderer.setDrawOutlines(true);
renderer.setUseFillPaint(true);
renderer.setFillPaint(Color.white);
*/
return chart;
}
@Override
protected GenericStandaloneGraph getInstance(String title) {
return new LineGraph(title);
}
}

View File

@ -1,149 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------------
* PieGraph.java
* ------------------
* (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.graphs;
import java.awt.Color;
import java.util.List;
import org.gcube.contentmanagement.graphtools.abstracts.GenericStandaloneGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYSplineRenderer;
import org.jfree.data.general.Dataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RectangleInsets;
public class NumericSeriesGraph extends GenericStandaloneGraph {
private static final long serialVersionUID = 1L;
public NumericSeriesGraph(String title) {
super(title);
}
protected Dataset generateDataset() {
XYSeries xyseries = new XYSeries("Series 1");
xyseries.add(2D, 56.270000000000003D);
xyseries.add(3D, 41.32D);
xyseries.add(4D, 31.449999999999999D);
xyseries.add(5D, 30.050000000000001D);
xyseries.add(6D, 24.690000000000001D);
xyseries.add(7D, 19.780000000000001D);
xyseries.add(8D, 20.940000000000001D);
xyseries.add(9D, 16.73D);
xyseries.add(10D, 14.210000000000001D);
xyseries.add(11D, 12.44D);
XYSeriesCollection xyseriescollection = new XYSeriesCollection(xyseries);
XYSeries xyseries1 = new XYSeries("Series 2");
xyseries1.add(11D, 56.270000000000003D);
xyseries1.add(10D, 41.32D);
xyseries1.add(9D, 31.449999999999999D);
xyseries1.add(8D, 30.050000000000001D);
xyseries1.add(7D, 24.690000000000001D);
xyseries1.add(6D, 19.780000000000001D);
xyseries1.add(5D, 20.940000000000001D);
xyseries1.add(4D, 16.73D);
xyseries1.add(3D, 14.210000000000001D);
xyseries1.add(2D, 12.44D);
xyseriescollection.addSeries(xyseries1);
return xyseriescollection;
}
protected JFreeChart createChart(Dataset dataset) {
NumberAxis numberaxis = new NumberAxis("X");
numberaxis.setAutoRangeIncludesZero(true);
NumberAxis numberaxis1 = new NumberAxis("Y");
numberaxis1.setAutoRangeIncludesZero(true);
XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
XYPlot xyplot = new XYPlot((XYDataset) dataset, numberaxis, numberaxis1, xysplinerenderer);
xyplot.setBackgroundPaint(Color.lightGray);
xyplot.setDomainGridlinePaint(Color.white);
xyplot.setRangeGridlinePaint(Color.white);
xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
JFreeChart chart = new JFreeChart("Numeric Series", JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);
return chart;
}
@Override
protected Dataset convert2Dataset(GraphData st) {
List<Point<? extends Number, ? extends Number>> pointslist = st.getData();
// NOTE: after the graph generation graphs are inverted in x and y
int numbOfRows = pointslist.size();
XYSeriesCollection xyseriescollection = new XYSeriesCollection();
if (numbOfRows > 0) {
int numbOfCols = pointslist.get(0).getEntries().size();
// calclulation will be made only for the first series
for (int x = 0; x < numbOfRows; x++) {
String serieslabel = pointslist.get(x).getLabel();
XYSeries xyseries = new XYSeries(serieslabel);
for (int y = 0; y < numbOfCols; y++) {
// String xlabel = pointslist.get(x).getEntries().get(y).getLabel();
double value = pointslist.get(x).getEntries().get(y).getValue().doubleValue();
xyseries.add(y + 1, value);
}
xyseriescollection.addSeries(xyseries);
}
}
return xyseriescollection;
}
@Override
protected GenericStandaloneGraph getInstance(String title) {
return new NumericSeriesGraph(title);
}
}

View File

@ -1,149 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------------
* PieGraph.java
* ------------------
* (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.graphs;
import java.util.List;
import org.gcube.contentmanagement.graphtools.abstracts.GenericStandaloneGraph;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.util.TableOrder;
public class PieGraph extends GenericStandaloneGraph {
private static final long serialVersionUID = 1L;
public PieGraph(String title) {
super(title);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
protected Dataset generateDataset() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("One", Double.valueOf(43.2));
dataset.setValue("Two", Double.valueOf(10.0));
dataset.setValue("Three", Double.valueOf(27.5));
dataset.setValue("Four", Double.valueOf(17.5));
dataset.setValue("Five", Double.valueOf(11.0));
dataset.setValue("Six", Double.valueOf(19.4));
return dataset;
}
/*
protected JFreeChart createChart(Dataset dataset) {
PiePlot plot = new PiePlot((DefaultPieDataset) dataset);
JFreeChart chart = new JFreeChart(plot);
return chart;
}
*/
protected JFreeChart createChart(Dataset dataset) {
JFreeChart chart = ChartFactory.createMultiplePieChart(
"Multiple Pie Chart", // chart title
(DefaultCategoryDataset)dataset, // dataset
TableOrder.BY_ROW,
true, // include legend
true,
false
);
return chart;
}
protected Dataset convert2DatasetOld(GraphData st) {
DefaultPieDataset dataset = new DefaultPieDataset();
List<Point<? extends Number, ? extends Number>> pointslist = st.getData();
// NOTE: after the graph generation graphs are inverted in x and y
int numbOfRows = pointslist.size();
if (numbOfRows > 0) {
int numbOfCols = pointslist.get(0).getEntries().size();
// calclulation will be made only for the first series
int x = 0;
String xlabel = pointslist.get(x).getLabel();
//calculate maximum
double max = 0;
for (int y = 0; y < numbOfCols; y++) {
double value = pointslist.get(x).getEntries().get(y).getValue().doubleValue();
if (value>max){
max = value;
}
}
for (int y = 0; y < numbOfCols; y++) {
double value = pointslist.get(x).getEntries().get(y).getValue().doubleValue();
value = (value/max)*100;
String ylabel = pointslist.get(x).getEntries().get(y).getLabel();
AnalysisLogger.getLogger().info(xlabel + ":" + ylabel +"->" + value);
dataset.setValue(xlabel + ":" + ylabel, value);
}
}
return dataset;
}
@Override
protected GenericStandaloneGraph getInstance(String title) {
return new PieGraph(title);
}
}

View File

@ -1,65 +0,0 @@
package org.gcube.contentmanagement.graphtools.plotting.graphs;
import org.gcube.contentmanagement.graphtools.abstracts.GenericStandaloneGraph;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.SpiderWebPlot;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;
public class RadarGraph extends GenericStandaloneGraph{
/**
*
*/
private static final long serialVersionUID = 1L;
public RadarGraph(String title) {
super(title);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
@Override
protected Dataset generateDataset() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(35.0, "S1", "C1");
dataset.addValue(45.0, "S1", "C2");
dataset.addValue(55.0, "S1", "C3");
dataset.addValue(15.0, "S1", "C4");
dataset.addValue(25.0, "S1", "C5");
dataset.addValue(39.0, "S2", "C1");
dataset.addValue(20.0, "S2", "C2");
dataset.addValue(34.0, "S2", "C3");
dataset.addValue(30.0, "S2", "C4");
dataset.addValue(13.0, "S2", "C5");
return dataset;
}
@Override
protected JFreeChart createChart(Dataset dataset) {
SpiderWebPlot plot = new SpiderWebPlot((DefaultCategoryDataset)dataset);
JFreeChart chart = new JFreeChart(plot);
return chart;
}
@Override
protected GenericStandaloneGraph getInstance(String title) {
return new RadarGraph(title);
}
}

View File

@ -1,131 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------------
* PieGraph.java
* ------------------
* (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.graphs;
import java.awt.BasicStroke;
import java.awt.Color;
import java.util.List;
import org.gcube.contentmanagement.graphtools.abstracts.GenericStandaloneGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
public class ScatterGraphGeneric extends GenericStandaloneGraph {
private static final long serialVersionUID = 1L;
public ScatterGraphGeneric(String title) {
super(title);
}
protected Dataset generateDataset() {
return null;
}
protected JFreeChart createChart(Dataset dataset) {
// create the chart...
JFreeChart chart = ChartFactory.createLineChart(
"", // chart title
"", // domain axis label
"", // range axis label
(DefaultCategoryDataset)dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.white);
CategoryPlot plot = chart.getCategoryPlot();
/*
plot.setDomainGridlineStroke(new BasicStroke(0.0F));
plot.setDomainGridlinePaint(Color.blue);
plot.setRangeGridlineStroke(new BasicStroke(0.0F));
plot.setRangeMinorGridlineStroke(new BasicStroke(0.0F));
plot.setRangeGridlinePaint(Color.blue);
plot.setRangeMinorGridlinesVisible(true);
plot.setNoDataMessage("NO DATA");
plot.setRangePannable(true);
plot.setRangeZeroBaselineVisible(true);
*/
plot.setBackgroundPaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setDomainCrosshairVisible(true);
plot.setDomainGridlinesVisible(false);
plot.setRangeCrosshairVisible(true);
plot.setRenderer(new LineAndShapeRenderer(false,true));
//deprecated
/*
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setShapesVisible(true);
renderer.setDrawOutlines(true);
renderer.setUseFillPaint(true);
renderer.setFillPaint(Color.white);
*/
return chart;
}
@Override
protected GenericStandaloneGraph getInstance(String title) {
return new ScatterGraphGeneric(title);
}
}

View File

@ -1,144 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------------
* PieGraph.java
* ------------------
* (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.graphs;
import java.awt.BasicStroke;
import java.awt.Color;
import java.util.List;
import org.gcube.contentmanagement.graphtools.abstracts.GenericStandaloneGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
public class ScatterGraphNumeric extends GenericStandaloneGraph {
private static final long serialVersionUID = 1L;
public ScatterGraphNumeric(String title) {
super(title);
}
protected Dataset generateDataset() {
return null;
}
protected JFreeChart createChart(Dataset dataset) {
JFreeChart jfreechart = ChartFactory.createScatterPlot("", "", "", (XYDataset)dataset, PlotOrientation.VERTICAL, true, true, false);
XYPlot xyplot = (XYPlot)jfreechart.getPlot();
xyplot.setNoDataMessage("NO DATA");
xyplot.setDomainPannable(true);
xyplot.setRangePannable(true);
xyplot.setDomainZeroBaselineVisible(true);
xyplot.setRangeZeroBaselineVisible(true);
xyplot.setDomainGridlineStroke(new BasicStroke(0.0F));
xyplot.setDomainMinorGridlineStroke(new BasicStroke(0.0F));
xyplot.setDomainGridlinePaint(Color.blue);
xyplot.setRangeGridlineStroke(new BasicStroke(0.0F));
xyplot.setRangeMinorGridlineStroke(new BasicStroke(0.0F));
xyplot.setRangeGridlinePaint(Color.blue);
xyplot.setDomainMinorGridlinesVisible(true);
xyplot.setRangeMinorGridlinesVisible(true);
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyplot.getRenderer();
xylineandshaperenderer.setSeriesOutlinePaint(0, Color.black);
xylineandshaperenderer.setUseOutlinePaint(true);
NumberAxis numberaxis = (NumberAxis)xyplot.getDomainAxis();
numberaxis.setAutoRangeIncludesZero(false);
numberaxis.setTickMarkInsideLength(2.0F);
numberaxis.setTickMarkOutsideLength(2.0F);
numberaxis.setMinorTickCount(2);
numberaxis.setMinorTickMarksVisible(true);
NumberAxis numberaxis1 = (NumberAxis)xyplot.getRangeAxis();
numberaxis1.setTickMarkInsideLength(2.0F);
numberaxis1.setTickMarkOutsideLength(2.0F);
numberaxis1.setMinorTickCount(2);
numberaxis1.setMinorTickMarksVisible(true);
return jfreechart;
}
@Override
protected Dataset convert2Dataset(GraphData st) {
List<Point<? extends Number, ? extends Number>> pointslist = st.getData();
// NOTE: after the graph generation graphs are inverted in x and y
int numbOfRows = pointslist.size();
XYSeriesCollection xyseriescollection = new XYSeriesCollection();
if (numbOfRows > 0) {
int numbOfCols = pointslist.get(0).getEntries().size();
// calculation will be made only for the first series
for (int x = 0; x < numbOfRows; x++) {
String serieslabel = pointslist.get(x).getLabel();
XYSeries xyseries = new XYSeries(serieslabel);
for (int y = 0; y < numbOfCols; y++) {
// String xlabel = pointslist.get(x).getEntries().get(y).getLabel();
double value = pointslist.get(x).getEntries().get(y).getValue().doubleValue();
xyseries.add(y + 1, value);
}
xyseriescollection.addSeries(xyseries);
}
}
return xyseriescollection;
}
@Override
protected GenericStandaloneGraph getInstance(String title) {
return new ScatterGraphNumeric(title);
}
}

View File

@ -1,186 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------------
* PieGraph.java
* ------------------
* (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.graphs;
import java.awt.Color;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import org.gcube.contentmanagement.graphtools.abstracts.GenericStandaloneGraph;
import org.gcube.contentmanagement.graphtools.utils.DateGuesser;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.general.Dataset;
import org.jfree.data.time.Day;
import org.jfree.data.time.Minute;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.RectangleInsets;
public class TimeSeriesGraph extends GenericStandaloneGraph {
private static final long serialVersionUID = 1L;
private static final String formatYear= "yyyy";
private static final String formatMonth= "MM-yyyy";
private static final String formatDay= "MM-dd-yyyy";
private String timeseriesformat;
public TimeSeriesGraph(String title) {
super(title);
}
protected Dataset generateDataset() {
TimeSeriesCollection dataset = new TimeSeriesCollection();
final TimeSeries s1 = new TimeSeries("Series 1");
s1.add(new Minute(0, 0, 7, 12, 2003), 1.2);
s1.add(new Minute(30, 12, 7, 12, 2003), 3.0);
s1.add(new Minute(15, 14, 7, 12, 2003), 8.0);
final TimeSeries s2 = new TimeSeries("Series 2");
s2.add(new Minute(0, 3, 7, 12, 2003), 0.0);
s2.add(new Minute(30, 9, 7, 12, 2003), 0.0);
s2.add(new Minute(15, 10, 7, 12, 2003), 0.0);
dataset.addSeries(s1);
dataset.addSeries(s2);
return dataset;
}
protected JFreeChart createChart(Dataset dataset) {
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Time Series", // title
"", // x-axis label
"", // y-axis label
(XYDataset)dataset, // data
true, // create legend?
true, // generate tooltips?
false // generate URLs?
);
chart.setBackgroundPaint(Color.white);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
XYItemRenderer r = plot.getRenderer();
if (r instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
renderer.setDrawSeriesLineAsPath(true);
}
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat(timeseriesformat));
return chart;
}
@Override
protected Dataset convert2Dataset(GraphData st) {
List<Point<? extends Number, ? extends Number>> pointslist = st.getData();
// NOTE: after the graph generation graphs are inverted in x and y
int numbOfRows = pointslist.size();
TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
if (numbOfRows > 0) {
int numbOfCols = pointslist.get(0).getEntries().size();
// calclulation will be made only for the first series
for (int x = 0; x < numbOfRows; x++) {
String serieslabel = pointslist.get(x).getLabel();
TimeSeries xyseries = new TimeSeries(serieslabel);
for (int y = 0; y < numbOfCols; y++) {
String xlabel = pointslist.get(x).getEntries().get(y).getLabel();
double value = pointslist.get(x).getEntries().get(y).getValue().doubleValue();
Calendar cal = DateGuesser.convertDate(xlabel);
String granularity = DateGuesser.granularity(xlabel);
if (granularity.equals(DateGuesser.YEAR)) timeseriesformat = formatYear;
else if (granularity.equals(DateGuesser.MONTH)) timeseriesformat = formatMonth;
else if (granularity.equals(DateGuesser.DAY)) timeseriesformat = formatDay;
AnalysisLogger.getLogger().debug("TimeSeriesGraph-> granularity "+granularity+" format "+timeseriesformat);
xyseries.add(new Day(new Date(cal.getTimeInMillis())),value);
}
timeseriescollection.addSeries(xyseries);
}
}
return timeseriescollection;
}
@Override
protected GenericStandaloneGraph getInstance(String title) {
TimeSeriesGraph tsg = new TimeSeriesGraph(title);
tsg.timeseriesformat = timeseriesformat;
return tsg;
}
}

View File

@ -1,293 +0,0 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------------
* PieGraph.java
* ------------------
* (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): ;
*
* Changes
* -------
* 09-Mar-2005 : Version 1, copied from the demo collection that ships with
* the JFreeChart Developer Guide (DG);
*
*/
package org.gcube.contentmanagement.graphtools.plotting.graphs;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import org.gcube.contentmanagement.graphtools.abstracts.GenericStandaloneGraph;
import org.gcube.contentmanagement.graphtools.utils.MathFunctions;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.AxisState;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.CategoryTick;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;
import org.jfree.text.TextBlock;
import org.jfree.text.TextBlockAnchor;
import org.jfree.text.TextLine;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
public class TransectLineGraph extends GenericStandaloneGraph {
private static final long serialVersionUID = 1L;
public TransectLineGraph(String title) {
super(title);
}
protected Dataset generateDataset() {
// row keys...
String series1 = "First";
String series2 = "Second";
String series3 = "Third";
// column keys...
String type1 = "Type 1";
String type2 = "Type 2";
String type3 = "Type 3";
String type4 = "Type 4";
String type5 = "Type 5";
String type6 = "Type 6";
String type7 = "Type 7";
String type8 = "Type 8";
// create the dataset...
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(1.0, series1, type1);
dataset.addValue(4.0, series1, type2);
dataset.addValue(3.0, series1, type3);
dataset.addValue(5.0, series1, type4);
dataset.addValue(5.0, series1, type5);
dataset.addValue(7.0, series1, type6);
dataset.addValue(7.0, series1, type7);
dataset.addValue(8.0, series1, type8);
dataset.addValue(5.0, series2, type1);
dataset.addValue(7.0, series2, type2);
dataset.addValue(6.0, series2, type3);
dataset.addValue(8.0, series2, type4);
dataset.addValue(4.0, series2, type5);
dataset.addValue(4.0, series2, type6);
dataset.addValue(2.0, series2, type7);
dataset.addValue(1.0, series2, type8);
dataset.addValue(4.0, series3, type1);
dataset.addValue(3.0, series3, type2);
dataset.addValue(2.0, series3, type3);
dataset.addValue(3.0, series3, type4);
dataset.addValue(6.0, series3, type5);
dataset.addValue(3.0, series3, type6);
dataset.addValue(4.0, series3, type7);
dataset.addValue(3.0, series3, type8);
return dataset;
}
protected JFreeChart createChart(Dataset dataset) {
DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
DefaultCategoryDataset dataset0 = (DefaultCategoryDataset)dataset;
ArrayList<Integer> relevantindexes = new ArrayList<Integer>();
for (Object row:dataset0.getRowKeys()){
int spikescounter=0;
int pointscounter=0;
int allcounter=0;
int mincolumns = 0;
int maxcolumns = dataset0.getColumnCount()-1;
int medcolumns = (maxcolumns)/2;
for (Object column:dataset0.getColumnKeys()){
// System.out.println("row "+row+" column "+column );
double value = dataset0.getValue((String)row, (String)column).doubleValue();
String xlab = (String) column;
String annotation ="";
String x1lab = xlab;
int commaindex = xlab.indexOf(";");
if (commaindex>0){
annotation = xlab.substring(commaindex+1);
x1lab = xlab.substring(0,commaindex);
dataset2.addValue(value, (String)row, ""+(allcounter+1)+": "+annotation);
spikescounter++;
relevantindexes.add(allcounter);
}
else{
if ((allcounter==mincolumns)||(allcounter==maxcolumns)||(allcounter==medcolumns))
relevantindexes.add(allcounter);
dataset2.addValue(value, (String)row, ""+(allcounter+1)+"");
pointscounter++;
}
allcounter++;
dataset1.addValue(value, (String)row, x1lab);
}
}
// create the chart...
JFreeChart chart = ChartFactory.createLineChart(
" ", // chart title
"", // domain axis label
"", // range axis label
(DefaultCategoryDataset)dataset1, // data
PlotOrientation.VERTICAL, // orientation
false, // include legend
true, // tooltips
false // urls
);
chart.setTitle(new TextTitle(" ", new Font("sansserif", Font.BOLD, 60)));
chart.setBackgroundPaint(Color.white);
CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setDomainCrosshairVisible(true);
plot.setDomainGridlinesVisible(true);
plot.setRangeCrosshairVisible(true);
// plot.setRenderer(new LineAndShapeRenderer(true,true));
plot.setRenderer(new LineAndShapeRenderer(true,false));
plot.setAxisOffset(new RectangleInsets(1D, 1D, 1D, 1D));
plot.setDomainAxis(0,new CustomXAxis("",dataset1,relevantindexes));
CategoryAxis categoryaxis1 = plot.getDomainAxis(0);
categoryaxis1.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
plot.mapDatasetToDomainAxis(0, 0);
plot.setDataset(1, (DefaultCategoryDataset)dataset2);
plot.setDomainAxis(1,new CustomXAxis("",dataset2,relevantindexes));
CategoryAxis categoryaxis2 = plot.getDomainAxis(1);
categoryaxis2.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
plot.mapDatasetToDomainAxis(1, 1);
plot.setDomainAxisLocation(1, AxisLocation.TOP_OR_LEFT);
// categoryaxis2.setLabelInsets(new RectangleInsets(100, 100, 100, 100));
// categoryaxis2.setLowerMargin(0.05D);
// categoryaxis2.setUpperMargin(1D);
// plot.mapDatasetToRangeAxis(1, 1);
//deprecated
/*
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setShapesVisible(true);
renderer.setDrawOutlines(true);
renderer.setUseFillPaint(true);
renderer.setFillPaint(Color.white);
*/
// rangeAxis.setStandardTickUnits(ValueAxis);
// rangeAxis.setAutoRangeIncludesZero(false);
// rangeAxis.setUpperMargin(0.12);
chart.setPadding(new RectangleInsets(30, 30, 90, 90));
big=true;
chart.getPlot().setBackgroundPaint(Color.white);
return chart;
}
@Override
protected GenericStandaloneGraph getInstance(String title) {
return new TransectLineGraph(title);
}
static class CustomXAxis extends CategoryAxis
{
DefaultCategoryDataset dataset;
List<Integer> samplingindexes;
public java.util.List refreshTicks(Graphics2D graphics2d, AxisState axisstate, Rectangle2D rectangle2d, RectangleEdge rectangleedge)
{
ArrayList arraylist = new ArrayList();
int size = dataset.getColumnCount();
for (int i=0;i<size;i++){
TextBlock tb = new TextBlock();
if (MathFunctions.isIn(samplingindexes, i)){
String xlab = (String)dataset.getColumnKeys().get(i);
// xlab = xlab.substring(xlab.indexOf(":")+1);
tb.addLine(new TextLine(xlab,new Font("sansserif", Font.BOLD, 8)));
}
else{
tb.addLine(new TextLine(""));
}
arraylist.add(new CategoryTick("p"+i, tb , TextBlockAnchor.CENTER_RIGHT,TextAnchor.CENTER_RIGHT, 0));
}
return arraylist;
}
public CustomXAxis(String s,DefaultCategoryDataset d,List<Integer> indexes)
{
super(s);
dataset = d;
samplingindexes = indexes;
}
}
}

View File

@ -1,64 +0,0 @@
package org.gcube.contentmanagement.graphtools.tests;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.GaussianDistributionGraph;
import org.gcube.contentmanagement.graphtools.plotting.graphs.HistogramGraph;
import org.gcube.contentmanagement.graphtools.plotting.graphs.LineGraph;
import org.gcube.contentmanagement.graphtools.plotting.graphs.PieGraph;
import org.gcube.contentmanagement.graphtools.plotting.graphs.RadarGraph;
import org.gcube.contentmanagement.graphtools.plotting.graphs.ScatterGraphGeneric;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class RegressionTestAllGraphs {
public static void main(String[] args) throws Exception{
String table = "rdm7d053300d89e11e087918065b36ddd05";
String xDimension = "field3";
String yDimension = "field5";
String groupDimension = "field2";
String linesColumn = "field4";
String filter1 = "Perciformes";
String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
LexicalEngineConfiguration conf = new LexicalEngineConfiguration();
//database Parameters
conf.setDatabaseURL("jdbc:postgresql://localhost/testdb");
conf.setDatabaseUserName("gcube");
conf.setDatabasePassword("d4science2");
conf.setDatabaseDriver("org.postgresql.Driver");
conf.setDatabaseDialect("org.hibernate.dialect.PostgreSQLDialect");
stg.init("./cfg/",conf);
// stg.addColumnFilter("field4", "F","=");
//String generation
GraphGroups gg = stg.generateGraphs(100, table, xDimension, yDimension, groupDimension, linesColumn, filter1, filter2);
//graph plot
RadarGraph series = new RadarGraph("");
series.renderGraphGroup(gg);
HistogramGraph series2 = new HistogramGraph("");
series2.renderGraphGroup(gg);
LineGraph series3 = new LineGraph("");
series3.renderGraphGroup(gg);
PieGraph series4 = new PieGraph("");
series4.renderGraphGroup(gg);
GaussianDistributionGraph series5 = new GaussianDistributionGraph("");
series5.renderGraphGroup(gg);
ScatterGraphGeneric series6 = new ScatterGraphGeneric("");
series6.renderGraphGroup(gg);
}
}

View File

@ -1,40 +0,0 @@
package org.gcube.contentmanagement.graphtools.tests.old;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.data.BigSamplesTable;
import org.gcube.contentmanagement.graphtools.plotting.graphs.TimeSeriesGraph;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
import com.rapidminer.RapidMiner;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.preprocessing.sampling.AbsoluteSampling;
import com.rapidminer.tools.OperatorService;
import com.rapidminer.tools.math.MathFunctions;
public class ExampleDerivative {
public static void main(String[] args) throws Exception{
String table = "ts_a904da30_b4fc_11df_800d_bcef80d51986";
String xDimension = "field1";
String yDimension = "field4";
String groupDimension = "field2";
String speciesColumn = "field3";
String filter1 = "Toluene";
// String filter2 = "Osteichthyes";
StatisticsGenerator stg = new StatisticsGenerator();
stg.init("./cfg/");
GraphGroups gg = stg.generateGraphs(200, table, xDimension, yDimension, groupDimension, speciesColumn, filter1);
TimeSeriesGraph series = new TimeSeriesGraph("");
series.renderGraphGroup(gg);
}
}

View File

@ -1,79 +0,0 @@
package org.gcube.contentmanagement.graphtools.tests.old;
import org.gcube.contentmanagement.graphtools.data.BigSamplesTable;
import com.rapidminer.RapidMiner;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.preprocessing.sampling.AbsoluteSampling;
import com.rapidminer.tools.OperatorService;
import com.rapidminer.tools.math.MathFunctions;
public class ExampleMathFunctions {
public static void main(String[] args) throws Exception{
double variance = MathFunctions.variance(new double[] { 0.1, 0.1, 0.0, -0.1 }, Double.NEGATIVE_INFINITY);
double covariance = MathFunctions.correlation(new double[] { 0.1, 0.2, -0.3, 0.0 }, new double[] { 0.0, 0.1, 0.1, -0.1 });
double meanc = mean(new double[] { 0.1, 0.1, 0.0, -0.1 });
// String pluginDirString = new File("C:/Users/coro/Desktop/WorkFolder/Workspace/RapidMinerPlugins/TextProcessing/Vega/lib/").getAbsolutePath();
// System.setProperty(RapidMiner.PROPERTY_RAPIDMINER_INIT_PLUGINS_LOCATION, pluginDirString);
System.setProperty("rapidminer.init.operators","C:/Users/coro/Desktop/WorkFolder/Workspace/RapidMiner_Wasat/resources/operators.xml");
RapidMiner.init ();
BigSamplesTable bst = new BigSamplesTable();
bst.addSampleRow("prova 1", 10, 12,13,14,15);
bst.addSampleRow("prova 2", 20, 15,14,15);
bst.addSampleRow("prova 3", 30, 11,110,150);
System.out.println(bst.toString());
// OperatorService.createOperator(ExampleSource.class);
// as.apply(bst.generateExampleSet());
// OperatorChain wvtoolOperator = (OperatorChain) OperatorService.createOperator(SingleTextInput.class);
// Learner learner = (Learner)OperatorService .createOperator("J48");
AbsoluteSampling as = (AbsoluteSampling)OperatorService .createOperator("AbsoluteSampling");
// SimpleSampling ss = (SimpleSampling)OperatorService .createOperator("Sampling");
// ss.setParameter("sample_ratio", "0.8");
as.setParameter("sample_size", "2");
as.setParameter("local_random_seed", "-1");
ExampleSet exampleSet = bst.generateExampleSet();
System.out.println(exampleSet.toResultString());
// ExampleSet exampleSetOut = ss.apply(exampleSet);
ExampleSet exampleSetOut = as.apply(exampleSet);
System.out.println(exampleSetOut.toResultString());
BigSamplesTable bstOut = new BigSamplesTable();
bstOut.generateSampleTable(exampleSetOut);
System.out.println(bstOut.toString());
// as.apply(es);
System.out.println("variance "+variance+" covariance "+covariance+" mean "+meanc);
}
//================================================= mean
public static double mean(double[] p) {
double sum = 0; // sum of all the elements
for (int i=0; i<p.length; i++) {
sum += p[i];
}
return sum / p.length;
}//end method mean
}

View File

@ -1,62 +0,0 @@
package org.gcube.contentmanagement.graphtools.tests.old;
import java.io.IOException;
import com.rapidminer.RapidMiner;
import com.rapidminer.example.Attribute;
import com.rapidminer.example.ExampleReader;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.IOContainer;
import com.rapidminer.operator.Model;
import com.rapidminer.operator.ModelApplier;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorCreationException;
import com.rapidminer.operator.OperatorException;
import com.rapidminer.operator.io.ExampleSource;
import com.rapidminer.operator.learner.Learner;
import com.rapidminer.tools.OperatorService;
public class ExampleOperatorsInvoking {
public static void main(String [] args) {
try {
System.setProperty("rapidminer.init.operators", "./cfg/operators.xml");
RapidMiner. init ();
// learn
Operator exampleSource = OperatorService .createOperator(ExampleSource.class);
exampleSource.setParameter(" attributes ",
"/path/to/your/training data .xml");
IOContainer container = exampleSource.apply(new IOContainer());
ExampleSet exampleSet = container.get(ExampleSet.class);
// here the string based creation must be used since the J48 operator
// do not have an own class ( derived from the Weka library ).
Learner learner = (Learner)OperatorService .createOperator("J48");
Model model = learner. learn (exampleSet);
// loading the test set (plus adding the model to result container )
Operator testSource = OperatorService .createOperator(ExampleSource.class);
testSource .setParameter(" attributes ", "/path/to/your/test data.xml");
container = testSource.apply(new IOContainer());
container = container.append(model);
// applying the model
Operator modelApp =
OperatorService .createOperator(ModelApplier.class );
container = modelApp.apply(container);
// print results
ExampleSet resultSet = container.get(ExampleSet.class);
// Attribute predictedLabel = resultSet.getPredictedLabel ();
// ExampleReader reader = resultSet.getExampleReader();
// while (reader .hasNext()) {
// System.out. println (reader .next (). getValueAsString( predictedLabel ));
// }
} catch (OperatorCreationException e) {
System.err . println ("Cannot create operator:" + e.getMessage());
} catch (OperatorException e) {
System.err . println ("Cannot create model: " + e.getMessage());
}
}
}

View File

@ -1,73 +0,0 @@
package org.gcube.contentmanagement.graphtools.tests.old;
import com.rapidminer.RapidMiner;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.IOContainer;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorException;
import com.rapidminer.operator.generator.ExampleSetGenerator;
import com.rapidminer.tools.OperatorService;
public class ExampleRMUsage {
/**
* @param args
*/
public static void main(String[] args) {
// create process
com.rapidminer.Process process = createProcess();
// print process setup
System.out. println (process .getRootOperator().createProcessTree (0));
try {
// perform process
process.run ();
// to run the process with input created by your application use
// process .run(new IOContainer(new IOObject[] f ... your objects ... g);
}catch (OperatorException e) { e. printStackTrace (); }
}
public static com.rapidminer.Process createProcess() {
System.out.println("INIT R-I");
// invoke init before using the OperatorService
RapidMiner.init();
System.out.println("INIT FINISHED");
// create process
com.rapidminer.Process process = new com.rapidminer.Process();
try {
// create operator
Operator inputOperator = OperatorService.createOperator(ExampleSetGenerator.class);
// set parameters
inputOperator.setParameter("target function", "sum classification");
// add operator to process
process.getRootOperator().addOperator(inputOperator,0);
// add other operators and set parameters
// [...]
System.out.println("INIT PROCESS FINISHED");
} catch (Exception e) {
e.printStackTrace();
}
return process;
}
public static IOContainer createInput () {
// create a wrapper that implements the ExampleSet interface and
// encapsulates your data
// ...
return new IOContainer();
}
}

View File

@ -1,58 +0,0 @@
package org.gcube.contentmanagement.graphtools.tests.old;
import java.util.LinkedList;
import java.util.List;
import com.rapidminer.example.Attribute;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.example.table.AttributeFactory;
import com.rapidminer.example.table.DoubleArrayDataRow;
import com.rapidminer.example.table.MemoryExampleTable;
import com.rapidminer.tools.Ontology;
public class ExampleUserSampleSet {
public static void main(String[] argv) {
// create attribute list
List<Attribute> attributes = new LinkedList<Attribute>();
for (int a = 0; a < getMyNumOfAttributes(); a++) {
attributes.add(AttributeFactory.createAttribute("att" + a, Ontology.REAL));
}
Attribute label = AttributeFactory.createAttribute(" label ", Ontology.NOMINAL);
attributes.add(label);
// create table
MemoryExampleTable table = new MemoryExampleTable(attributes);
// ll table (here : only real values )
for (int d = 0; d < getMyNumOfDataRows(); d++) {
double[] data = new double[attributes.size()];
for (int a = 0; a < getMyNumOfAttributes(); a++) {
// all with proper data here
data[a] = getMyValue(d, a);
}
// maps the nominal classi cation to a double value
data[data.length - 1] = label.getMapping().mapString(getMyClassification(d));
// add data row
table.addDataRow(new DoubleArrayDataRow(data));
}
// create example set
ExampleSet exampleSet = table.createExampleSet(label);
}
//to be defined in future applications
private static int getMyNumOfAttributes() {
return 3;
}
private static int getMyNumOfDataRows() {
return 10;
}
private static double getMyValue(int d, int a) {
return 10;
}
private static String getMyClassification(int d) {
return "ciao";
}
}

View File

@ -1,70 +0,0 @@
package org.gcube.contentmanagement.graphtools.tests.old;
import java.util.List;
import org.gcube.contentmanagement.graphtools.data.BigSamplesTable;
import org.gcube.contentmanagement.graphtools.data.conversions.GraphConverter2D;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
public class TestConverters {
public static void main1(String[] args) throws Exception{
BigSamplesTable bst = new BigSamplesTable();
bst.addSampleRow("prova 1", 10, 15);
bst.addSampleRow("prova 2", 10, 12);
bst.addSampleRow("prova 3", 30, 11);
bst.addSampleRow("prova 1", 10, 15);
bst.addSampleRow("prova 2", 10, 12);
bst.addSampleRow("prova 3", 30, 11);
bst.addSampleRow("prova 1", 10, 15);
bst.addSampleRow("prova 2", 10, 12);
bst.addSampleRow("prova 3", 30, 11);
bst.addSampleRow("prova 1", 10, 15);
bst.addSampleRow("prova 2", 10, 12);
bst.addSampleRow("prova 3", 30, 11);
bst.addSampleRow("prova 1", 10, 15);
bst.addSampleRow("prova 2", 10, 12);
bst.addSampleRow("prova 3", 30, 11);
bst.addSampleRow("prova 1", 10, 15);
bst.addSampleRow("prova 2", 10, 12);
bst.addSampleRow("prova 3", 30, 11);
bst.addSampleRow("prova 1", 10, 15);
bst.addSampleRow("prova 2", 10, 12);
bst.addSampleRow("prova 3", 30, 11);
System.out.println(bst.toString());
List<Point<? extends Number, ? extends Number>> graphicus = GraphConverter2D.convert(bst);
graphicus = GraphConverter2D.reduceDimension(graphicus);
System.out.println("finished!");
}
public static void main(String[] args) throws Exception{
BigSamplesTable bst = new BigSamplesTable();
bst.addSampleRow("1;prova y1", 0, 0);
bst.addSampleRow("1;prova y2", 0, 0);
bst.addSampleRow("1;prova y3", 0, 0);
bst.addSampleRow("prova 1;prova y1", 10, 15);
bst.addSampleRow("prova 2;prova y2", 10, 12);
bst.addSampleRow("prova 3;prova y2", 30, 11);
bst.addSampleRow("prova 3;prova y1", 30, 10);
System.out.println(bst.toString());
List<Point<? extends Number, ? extends Number>> graphicus = GraphConverter2D.convert(bst);
graphicus = GraphConverter2D.reduceDimension(graphicus);
System.out.println("finished!");
}
}

View File

@ -1,55 +0,0 @@
package org.gcube.contentmanagement.graphtools.tests.old;
import java.util.List;
import java.util.Map;
import org.gcube.contentmanagement.graphtools.abstracts.SamplesTable;
import org.gcube.contentmanagement.graphtools.data.conversions.GraphConverter2D;
import org.gcube.contentmanagement.graphtools.data.databases.CommonDBExtractor;
import org.gcube.contentmanagement.lexicalmatcher.utils.DatabaseFactory;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphData;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
import org.hibernate.SessionFactory;
public class TestDBExtractor {
public static void main(String[] args) throws Exception{
SessionFactory referenceDBSession = DatabaseFactory.initDBConnection("./hibernate.cfg.xml");
CommonDBExtractor extractor = new CommonDBExtractor(referenceDBSession);
String table = "ts_161efa00_2c32_11df_b8b3_aa10916debe6";
String xDimension = "field5";
String groupDimension = "field1";
String yValue = "field6";
String speciesColumn = "field3";
String filter1 = "Brown seaweeds";
String filter2 = "River eels";
Map<String, SamplesTable> samplesMap = extractor.getMultiDimTemporalTables(table, xDimension, groupDimension, yValue, speciesColumn, filter1, filter2);
System.out.println("MAP EXTRACTED : \n"+samplesMap.toString());
GraphGroups graphgroups = new GraphGroups();
for (String key:samplesMap.keySet()){
SamplesTable stable = samplesMap.get(key);
List<Point<? extends Number, ? extends Number>> singlegraph = GraphConverter2D.transformTable(stable);
GraphData grd = new GraphData(singlegraph,true);
graphgroups.addGraph("Distribution for "+key, grd);
}
System.out.println("finished!");
}
}

View File

@ -1,40 +0,0 @@
package org.gcube.contentmanagement.graphtools.tests.old;
import java.io.File;
import com.rapidminer.RapidMiner;
import com.rapidminer.operator.IOContainer;
import com.rapidminer.operator.Model;
import com.rapidminer.operator.ModelApplier;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorChain;
import com.rapidminer.operator.io.ModelLoader;
import com.rapidminer.tools.OperatorService;
public class TextTest {
public static void main(String[] argv) throws Exception {
String pluginDirString = new File("C:\\Dokumente und Einstellungen\\Mierswa\\Eigene Dateien\\workspace\\RMTextTest\\lib").getAbsolutePath();
System.setProperty(RapidMiner.PROPERTY_RAPIDMINER_INIT_PLUGINS_LOCATION, pluginDirString);
File wordListFile = new File(".");
File modelFile = new File(".");
RapidMiner.init();
/*
OperatorChain wvtoolOperator = (OperatorChain) OperatorService.createOperator(SingleTextInput.class);
wvtoolOperator.setParameter("input_word_list", wordListFile.getAbsolutePath());
wvtoolOperator.addOperator(OperatorService.createOperator(SimpleTokenizer.class));
wvtoolOperator.addOperator(OperatorService.createOperator(PorterStemmer.class));
Operator modelApplier = OperatorService.createOperator(ModelApplier.class);
Operator modelLoader = OperatorService.createOperator(ModelLoader.class);
modelLoader.setParameter(ModelLoader.PARAMETER_MODEL_FILE, modelFile.getAbsolutePath());
IOContainer container = modelLoader.apply(new IOContainer());
Model model = container.get(Model.class);
*/
}
}

View File

@ -1,61 +0,0 @@
package org.gcube.contentmanagement.graphtools.tests.show;
import org.gcube.contentmanagement.graphtools.core.StatisticsGenerator;
import org.gcube.contentmanagement.graphtools.plotting.graphs.GaussianDistributionGraph;
import org.gcube.contentmanagement.graphtools.plotting.graphs.HistogramGraph;
import org.gcube.contentmanagement.graphtools.plotting.graphs.LineGraph;
import org.gcube.contentmanagement.graphtools.plotting.graphs.PieGraph;
import org.gcube.contentmanagement.graphtools.plotting.graphs.RadarGraph;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
import org.gcube.portlets.user.timeseries.charts.support.types.GraphGroups;
public class ExampleStringGraphData {
public static void main(String[] args) throws Exception{
String table = "ts_3637f670_430c_11df_a0a2_909e7d074592";
String xDimension = "field5";
String yDimension = "field6";
String groupDimension = "field1";
String speciesColumn = "field3";
String filter1 = "Crabs, sea-spiders";
String filter2 = "Marine fishes not identified";
StatisticsGenerator stg = new StatisticsGenerator();
LexicalEngineConfiguration conf = new LexicalEngineConfiguration();
//database Parameters
conf.setDatabaseUserName("root");
// conf.setDatabasePassword("password");
conf.setDatabaseDriver("com.mysql.jdbc.Driver");
conf.setDatabaseURL("jdbc:mysql://localhost/timeseries");
conf.setDatabaseDialect("org.hibernate.dialect.MySQLDialect");
conf.setDatabaseAutomaticTestTable("connectiontesttable");
conf.setDatabaseIdleConnectionTestPeriod("3600");
stg.init("./cfg/",conf);
stg.addColumnFilter("field4", "F","=");
//String generation
GraphGroups gg = stg.generateGraphs(100, table, xDimension, yDimension, groupDimension, speciesColumn, filter1, filter2);
//graph plot
RadarGraph series = new RadarGraph("");
series.renderGraphGroup(gg);
HistogramGraph series2 = new HistogramGraph("");
series2.renderGraphGroup(gg);
LineGraph series3 = new LineGraph("");
series3.renderGraphGroup(gg);
PieGraph series4 = new PieGraph("");
series4.renderGraphGroup(gg);
GaussianDistributionGraph series5 = new GaussianDistributionGraph("");
series5.renderGraphGroup(gg);
}
}

View File

@ -1,44 +0,0 @@
package org.gcube.contentmanagement.graphtools.tests;
import java.util.List;
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.contentmanagement.lexicalmatcher.utils.DatabaseFactory;
import org.hibernate.SessionFactory;
public class testConnections {
public static void main(String args[]) throws Exception{
LexicalEngineConfiguration conf = new LexicalEngineConfiguration();
conf.setDatabaseURL("jdbc:postgresql://localhost/testdb");
conf.setDatabaseUserName("gcube");
conf.setDatabasePassword("d4science2");
conf.setDatabaseDriver("org.postgresql.Driver");
conf.setDatabaseDialect("org.hibernate.dialect.PostgreSQLDialect");
String hibernateDefaultFile = "hibernate.cfg.xml";
String loggerDefaultFile = "ALog.properties";
String configPath = "./cfg/";
AnalysisLogger.setLogger(configPath+loggerDefaultFile);
SessionFactory session = DatabaseFactory.initDBConnection(configPath+hibernateDefaultFile,conf);
List<Object> resultSet = DatabaseFactory.executeSQLQuery("select * from hcaf_s limit 10", session);
for (Object result:resultSet){
Object [] row = (Object[]) result;
for (int i=0;i<row.length;i++){
System.out.print(""+row[i]+" ");
}
System.out.println();
}
// DatabaseFactory.executeSQLUpdate("set ... ", session);
session.close();
}
}

View File

@ -1,151 +0,0 @@
package org.gcube.contentmanagement.graphtools.utils;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class DateGuesser {
public static void main(String[] args) {
Calendar c = convertDate("20/2/2010 0:49:00");
System.out.println("giorno " + c.get(Calendar.DAY_OF_MONTH) + " mese " + (c.get(Calendar.MONTH) + 1) + " anno " + c.get(Calendar.YEAR));
System.out.println("pattern "+getPattern("20/2/2010 0:49:00") );
System.out.println("pattern "+getPattern("2009-05-12 15:42:10") );
System.out.println("pattern "+getPattern("1970") );
System.out.println("pattern "+getPattern("2009-05-12") );
System.out.println("pattern "+getPattern("prova") );
System.out.println("pattern "+getPattern("9/26/2010 1:49:00"));
c = convertDate("2009-05-12");
System.out.println("giorno " + c.get(Calendar.DAY_OF_MONTH) + " mese " + (c.get(Calendar.MONTH) + 1) + " anno " + c.get(Calendar.YEAR));
// Properties prop = new Properties(System.getProperties());
// prop.list(System.out);
}
public static Calendar convertDate(String data) {
return convertDate(data,null);
}
public static String getPattern(String data) {
return getPattern(data,null);
}
// private static final String[] formats = { "MM\\dd\\yyyy", "MM\\dd\\yy", "MM/dd/yy", "MM/dd/yyyy", "dd/MM/yy", "dd/MM/yyyy", "dd/MM/yyyy HH:mm:ss", "dd/MM/yy HH:mm:ss", "dd/MM/yyyy HH:mm:ss","MM/yy","MM/yyyy", "yyyy.MM.dd G 'at' HH:mm:ss z", "EEE, MMM d, ''yy", "h:mm a", "hh 'o''clock' a, zzzz", "K:mm a, z", "MM-dd-yy","MM-dd-yyyy", "dd-MMM-yy", "yyyy.MM.dd.HH.mm.ss", "E, dd MMM yyyy HH:mm:ss Z", "yyyyy.MMMMM.dd GGG hh:mm aaa", "EEE, d MMM yyyy HH:mm:ss Z", "yyMMddHHmmssZ", "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd HH:mm","yyyy-MM-dd","yyyy-MM-dd HH:mm:ss", "h:mm a", "yyyy"};
private static final String[] formats = { "MM\\dd\\yyyy", "MM\\dd\\yy", "MM/dd/yy", "MM/dd/yyyy", "MM/yy","MM/yyyy", "yyyy.MM.dd G 'at' HH:mm:ss z", "MM/dd/yyyy HH:mm:ss","MM/dd/yyyy HH:mm:ss aaa","dd/MM/yyyy HH:mm:ss","EEE, MMM d, ''yy", "h:mm a", "hh 'o''clock' a, zzzz", "K:mm a, z", "MM-dd-yy","MM-dd-yyyy", "dd-MMM-yy", "yyyy.MM.dd.HH.mm.ss", "E, dd MMM yyyy HH:mm:ss Z", "yyyyy.MMMMM.dd GGG hh:mm aaa", "EEE, d MMM yyyy HH:mm:ss Z", "yyMMddHHmmssZ", "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd HH:mm","yyyy-MM-dd","yyyy-MM-dd HH:mm:ss", "h:mm a", "yyyy"};
private static final String[] formatiITA = { "dd\\MM\\yyyy", "dd\\MM\\yy", "dd/MM/yy", "dd/MM/yyyy", "dd/MM/yy", "dd/MM/yyyy","dd/MM/yyyy HH:mm:ss", "dd/MM/yy HH:mm:ss", "dd/MM/yyyy HH:mm:ss", "MM/yy","MM/yyyy","dd.MM.yyyy G 'alle' HH:mm:ss z", "EEE, MMM d, ''yy", "h:mm a", "hh a, zzzz", "K:mm a, z", "dd-MMM-yy", "dd.MM.yyyy.HH.mm.ss", "E, dd MMM yyyy HH:mm:ss Z", "yyyyy.MMMMM.dd GGG hh:mm aaa", "EEE, d MMM yyyy HH:mm:ss Z", "yyMMddHHmmssZ", "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "dd-MMM-yyyy HH:mm", "h:mm a", "yyyy"};
public static String getPattern(String data, String language) {
//String language = System.getProperty("user.language");
Locale l = Locale.UK;
if (language!=null && language.equalsIgnoreCase("it"))
l = Locale.ITALY;
Date dat = null;
DateFormat formatter = null;
String[] formati = formats;
if (l.equals(Locale.ITALY))
formati = formatiITA;
int index = -1;
for (int i = 0; i < formati.length; i++) {
try {
formatter = new SimpleDateFormat(formati[i],l);
dat = (Date) formatter.parse(data);
if (index == -1)
index = i;
else if (formati[index].length()<=formati[i].length())
index = i;
// System.out.println(formati[i]);
} catch (Exception e) {
// e.printStackTrace();
}
}
if (dat!=null){
return formati[index];
}
else
return null;
}
public static Calendar convertDate(String data, String language) {
//String language = System.getProperty("user.language");
Locale l = Locale.UK;
if (language!=null && language.equalsIgnoreCase("it"))
l = Locale.ITALY;
Date dat = null;
DateFormat formatter = null;
String[] formati = formats;
if (l.equals(Locale.ITALY))
formati = formatiITA;
int index = -1;
Date bestDate = null;
for (int i = 0; i < formati.length; i++) {
try {
formatter = new SimpleDateFormat(formati[i],l);
dat = (Date) formatter.parse(data);
if (index==-1){
bestDate = dat;
index = i;
}
else if (formati[index].length()<=formati[i].length()){
bestDate = dat;
index = i;
}
// break;
} catch (Exception e) {
// e.printStackTrace();
}
}
if (bestDate!=null){
Calendar c = Calendar.getInstance();
c.setTime(bestDate);
// System.out.println("data "+data+" giorno " + c.get(Calendar.DAY_OF_MONTH) + " mese " + (c.get(Calendar.MONTH) + 1) + " anno " + c.get(Calendar.YEAR));
return c;
}
else
return null;
}
public static final String YEAR = "YEAR";
public static final String MONTH = "MONTH";
public static final String DAY = "DAY";
public static String granularity(String pattern) {
SimpleDateFormat formatter = null;
try{
formatter = new SimpleDateFormat("MM/dd/yyyy");
formatter.parse(pattern);
return DAY;
}catch(Exception e){}
try{
formatter = new SimpleDateFormat("MM/yyyy");
formatter.parse(pattern);
return MONTH;
}catch(Exception e){}
try{
formatter = new SimpleDateFormat("MM/yy");
formatter.parse(pattern);
return MONTH;
}catch(Exception e){}
return YEAR;
}
}

View File

@ -1,282 +0,0 @@
package org.gcube.contentmanagement.graphtools.utils;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Type;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import com.google.gson.Gson;
public class HttpRequest {
/**
* Sends an HTTP GET request to a url
*
* @param endpoint
* - The URL of the server. (Example: " http://www.yahoo.com/search")
* @param requestParameters
* - all the request parameters (Example: "param1=val1&param2=val2"). Note: This method will add the question mark (?) to the request - DO NOT add it yourself
* @return - The response from the end point
*/
public static String sendGetRequest(String endpoint, String requestParameters) {
String result = null;
if (endpoint.startsWith("http://")) {
// Send a GET request to the servlet
try {
// Send data
String urlStr = endpoint;
if (requestParameters != null && requestParameters.length() > 0) {
urlStr += "?" + requestParameters;
}
URL url = new URL(urlStr);
URLConnection conn = url.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
result = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
/**
* Reads data from the data reader and posts it to a server via POST request. data - The data you want to send endpoint - The server's address output - writes the server's response to output
*
* @throws Exception
*/
public static void postData(Reader data, URL endpoint, Writer output) throws Exception {
HttpURLConnection urlc = null;
try {
urlc = (HttpURLConnection) endpoint.openConnection();
try {
urlc.setRequestMethod("POST");
} catch (ProtocolException e) {
throw new Exception("Shouldn't happen: HttpURLConnection doesn't support POST??", e);
}
urlc.setDoOutput(true);
urlc.setDoInput(true);
urlc.setUseCaches(false);
urlc.setAllowUserInteraction(false);
urlc.setRequestProperty("Content-type", "text/xml; charset=" + "UTF-8");
OutputStream out = urlc.getOutputStream();
try {
Writer writer = new OutputStreamWriter(out, "UTF-8");
pipe(data, writer);
writer.close();
} catch (IOException e) {
throw new Exception("IOException while posting data", e);
} finally {
if (out != null)
out.close();
}
InputStream in = urlc.getInputStream();
try {
Reader reader = new InputStreamReader(in);
pipe(reader, output);
reader.close();
} catch (IOException e) {
throw new Exception("IOException while reading response", e);
} finally {
if (in != null)
in.close();
}
} catch (IOException e) {
throw new Exception("Connection error (is server running at " + endpoint + " ?): " + e);
} finally {
if (urlc != null)
urlc.disconnect();
}
}
// performs a simple Get from a remote url
public static Object getJSonData(String endpoint, String requestParameters, Type outputClass) throws Exception {
String output = sendGetRequest(endpoint, requestParameters);
Gson gson = new Gson();
// AnalysisLogger.getLogger().debug("HttpRequest-> OUTPUT JSON:\n"+output.toString());
// Output the response
Object rebuiltJson = gson.fromJson(output.toString(), outputClass);
return rebuiltJson;
}
// performs a simple transformation to a json object
public static String toJSon(Object obj) {
Gson gson = new Gson();
String jsonString = gson.toJson(obj);
return jsonString;
}
public static Object postJSonData(String endpoint, Object obj, Type outputClass) throws Exception {
HttpURLConnection urlc = null;
try {
// Send the request
URL url = new URL(endpoint);
urlc = (HttpURLConnection) url.openConnection();
try {
urlc.setRequestMethod("POST");
} catch (ProtocolException e) {
throw new Exception("Error in HttpURLConnection", e);
}
urlc.setDoOutput(true);
urlc.setDoInput(true);
urlc.setUseCaches(false);
urlc.setAllowUserInteraction(false);
urlc.setRequestProperty("Content-type", "application/json; charset=" + "UTF-8");
OutputStreamWriter writer = null;
Gson gson = new Gson();
if (obj != null) {
OutputStream out = urlc.getOutputStream();
writer = new OutputStreamWriter(out);
// write parameters
String jsonString = gson.toJson(obj);
AnalysisLogger.getLogger().trace("INPUT JSON:\n" + jsonString);
writer.write(jsonString);
writer.flush();
}
// Get the response
StringBuffer answer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
answer.append(line);
}
if (obj != null)
writer.close();
reader.close();
// AnalysisLogger.getLogger().debug("OUTPUT JSON:\n"+answer.toString());
// Output the response
Object rebuiltJson = gson.fromJson(answer.toString(), outputClass);
return rebuiltJson;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
/**
* Pipes everything from the reader to the writer via a buffer
*/
private static void pipe(Reader reader, Writer writer) throws IOException {
char[] buf = new char[1024];
int read = 0;
while ((read = reader.read(buf)) >= 0) {
writer.write(buf, 0, read);
}
writer.flush();
}
public static String sendPostRequest(String endpoint, String requestParameters) {
// Build parameter string
String data = requestParameters;
try {
// Send the request
URL url = new URL(endpoint);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
// write parameters
writer.write(data);
writer.flush();
// Get the response
StringBuffer answer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
answer.append(line);
}
writer.close();
reader.close();
// Output the response
return answer.toString();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
public static String ManageCDATA(String phrase) {
return phrase.replace("<![CDATA[", "").replace("]]>", "");
}
public static String AddCDATA(String phrase) {
return "<![CDATA[" + phrase + "]]>";
}
public static int checkUrl(String url, final String username, final String password) {
int checkConn = -1;
try {
if ((username != null) && (password != null)) {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
});
}
URL checkurl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) checkurl.openConnection();
checkConn = conn.getResponseCode();
conn.disconnect();
} catch (Exception e) {
System.out.println("ERROR in URL " + e.getMessage());
}
return checkConn;
}
public static void main(String[] args) {
String url = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geoserver/rest/layergroups/group4402c0cff-27e3-4606-a2f1-993ad37c3dfb.json";
int d = checkUrl(url, "admin", "gcube@geo2010");
System.out.println(d);
}
}

View File

@ -1,253 +0,0 @@
package org.gcube.contentmanagement.graphtools.utils;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.user.timeseries.charts.support.types.Point;
public class MathFunctions {
/**
* @param args
*/
public static void main(String[] args) {
/*
double[] a = logSubdivision(1,4874,5);
for (int i =0;i<a.length;i++){
System.out.print(a[i]+" ");
}
*/
System.out.println(" "+roundDecimal(300.23454,2));
}
//rounds to the xth decimal position
public static double roundDecimal(double number,int decimalposition){
double n = (double)Math.round(number * Math.pow(10.00,decimalposition))/Math.pow(10.00,decimalposition);
return n;
}
// increments a percentage o mean calculation when a lot of elements are present
public static float incrementPerc(float perc, float quantity, int N) {
if (N == 0)
return quantity;
float out = 0;
int N_plus_1 = N + 1;
out = (float) ((perc + ((double) quantity / (double) N)) * ((double) N / (double) N_plus_1));
return out;
}
public static ArrayList<Integer> generateRandoms(int numberOfRandoms, int min, int max) {
ArrayList<Integer> randomsSet = new ArrayList<Integer>();
// if number of randoms is equal to -1 generate all numbers
if (numberOfRandoms == -1) {
for (int i = min; i < max; i++) {
randomsSet.add(i);
}
} else {
int numofrandstogenerate = 0;
if (numberOfRandoms <= max) {
numofrandstogenerate = numberOfRandoms;
} else {
numofrandstogenerate = max;
}
if (numofrandstogenerate == 0) {
randomsSet.add(0);
} else {
for (int i = 0; i < numofrandstogenerate; i++) {
int RNum = -1;
RNum = (int) ((max) * Math.random()) + min;
// generate random number
while (randomsSet.contains(RNum)) {
RNum = (int) ((max) * Math.random()) + min;
// AnalysisLogger.getLogger().debug("generated " + RNum);
}
// AnalysisLogger.getLogger().debug("generated " + RNum);
if (RNum >= 0)
randomsSet.add(RNum);
}
}
}
return randomsSet;
}
public static int[] generateSequence(int elements) {
int[] sequence = new int[elements];
for (int i = 0; i < elements; i++) {
sequence[i] = i;
}
return sequence;
}
public static BigInteger chunk2Index(int chunkIndex, int chunkSize) {
return BigInteger.valueOf(chunkIndex).multiply(BigInteger.valueOf(chunkSize));
}
// calculates mean
public static double mean(double[] p) {
double sum = 0; // sum of all the elements
for (int i = 0; i < p.length; i++) {
sum += p[i];
}
return sum / p.length;
}// end method mean
//calculates normalized derivative
public static double[] derivative(double[] a) {
double[] d = new double[a.length];
double max = 1;
if (a.length > 0) {
for (int i = 0; i < a.length; i++) {
double current = a[i];
double previous = current;
if (i > 0) {
previous = a[i - 1];
}
d[i] = current - previous;
if (Math.abs(d[i])>max)
max = Math.abs(d[i]);
// System.out.println("point "+a[i]+" derivative "+d[i]);
}
//normalize
for (int i = 0; i < a.length; i++) {
d[i] = d[i]/max;
}
}
return d;
}
// returns a list of spikes indexes
public static boolean[] findSpikes(double[] derivative,double threshold) {
boolean[] d = new boolean[derivative.length];
if (d.length > 0) {
d[0] = false;
for (int i = 1; i < derivative.length - 1; i++) {
if (derivative[i] / derivative[i + 1] < 0){
// double ratio = Math.abs((double) derivative[i]/ (double) derivative[i+1]);
// System.out.println("RATIO "+i+" "+Math.abs(derivative[i]));
// if ((threshold>0)&&(ratio<threshold))
if ((threshold>0)&&(Math.abs(derivative[i])>threshold))
d[i] = true;
}
else
d[i] = false;
}
d[derivative.length - 1] = false;
}
return d;
}
// returns a list of spikes indexes
public static boolean[] findSpikes(double[] derivative) {
return findSpikes(derivative,-1);
}
// transforms a list of points for a series in a double vector of y values
// it applies ONLY to transposed graphs not to extracted list of points (see GraphSamplesTable)
public static double[] points2Double(List<Point<? extends Number, ? extends Number>> pointslist, int seriesIndex, int numbOfPoints) {
double[] points = new double[numbOfPoints];
// System.out.print("points: ");
for (int y = 0; y < numbOfPoints; y++) {
double value = pointslist.get(seriesIndex).getEntries().get(y).getValue().doubleValue();
points[y] = value;
// System.out.print(value+" ");
}
return points;
}
// searches for an index into an array
public static boolean isIn(List<Integer> indexarray, int index) {
int size = indexarray.size();
for (int i = 0; i < size; i++) {
if (index == indexarray.get(i).intValue())
return true;
}
return false;
}
// finds the indexes of zero points
public static List<Integer> findZeros(double[] points) {
int size = points.length;
ArrayList<Integer> zeros = new ArrayList<Integer>();
for (int i = 0; i < size; i++) {
if (points[i]==0){
int start = i;
int end = i;
for (int j=i+1;j<size;j++)
{
if (points[j]!=0){
end = j-1;
break;
}
}
int center = start+((end-start)/2);
zeros.add(center);
i = end;
}
}
return zeros;
}
public static double[] logSubdivision(double start,double end,int numberOfParts){
if (end<=start)
return null;
if (start == 0){
start = 0.01;
}
double logStart = Math.log(start);
double logEnd = Math.log(end);
double step =0 ;
if (numberOfParts >0){
double difference = logEnd-logStart;
step = (difference/(double)numberOfParts);
}
// double [] points = new double[numberOfParts+1];
double[] linearpoints = new double[numberOfParts+1];
for (int i=0;i<numberOfParts+1;i++){
// points[i] = logStart+(i*step);
linearpoints[i]= Math.exp(logStart+(i*step));
if (linearpoints[i]<0.011)
linearpoints[i] = 0;
}
return linearpoints;
}
}

View File

@ -1,117 +0,0 @@
package org.gcube.contentmanagement.lexicalmatcher.analysis.core;
import java.math.BigDecimal;
import java.util.ArrayList;
public class DataTypeRecognizer {
// if the DB type contains one of this, org.gcube.contentmanagement.lexicalmatcher will be classified as Decimal
private static String[] decimalType = { "decimal", "integer", "int", "ordinal", "length", "position" ,"real"};
private static String[] booleanType = { "bool" };
private static String[] stringType = { "varchar", "char", "string", "text" };
public static String transformTypeFromDB(String DBType) {
// check if the db type is yet known
String type = null;
try {
// check if org.gcube.contentmanagement.lexicalmatcher is a char
if (contains(DBType, stringType)) {
type = String.class.getName();
}
// check if org.gcube.contentmanagement.lexicalmatcher is a decimal
else if (contains(DBType, decimalType))
type = BigDecimal.class.getName();
// check if org.gcube.contentmanagement.lexicalmatcher is a boolean
else if (contains(DBType, booleanType))
type = Boolean.class.getName();
else
type = String.class.getName();
} catch (Exception e) {
type = String.class.getName();
}
return type;
}
// guesses the type of an object
public static Object guessType(String entry) {
Object type = null;
// try to transform to a double
try {
double d = Double.parseDouble(entry);
type = BigDecimal.valueOf(d);
} catch (Exception eD) {
// try to transform to a boolean
if (entry.equalsIgnoreCase("true") || (entry.equalsIgnoreCase("false"))) {
boolean b = Boolean.parseBoolean(entry);
type = Boolean.valueOf(b);
} else
type = entry;
}
return type;
}
private static boolean contains(String element, String[] array) {
element = element.toLowerCase();
for (String arrayElem : array) {
if (element.contains(arrayElem)) {
return true;
}
}
return false;
}
public static String guessType(ArrayList<String> elementlist) {
// 0 = String 1 = Boolean 2 = Decimal
int[] scores = new int[3];
String[] types = { String.class.getName(), Boolean.class.getName(), BigDecimal.class.getName() };
for (String element : elementlist) {
Object guessedObj = guessType(element);
if (guessedObj instanceof String) {
scores[0] = scores[0] + 1;
} else if (guessedObj instanceof Boolean) {
scores[1] = scores[1] + 1;
} else if (guessedObj instanceof BigDecimal) {
scores[2] = scores[2] + 1;
}
}
int max = -1;
int maxindex = -1;
for (int i = 0; i < scores.length; i++) {
if (scores[i] > max) {
max = scores[i];
maxindex = i;
}
}
// System.out.println("index " + maxindex + " max " + max);
String type = types[maxindex];
return type;
}
public static void main(String[] args) throws ClassNotFoundException {
ArrayList<String> prova = new ArrayList<String>();
for (int i = 0; i < 5; i++) {
prova.add("1234");
}
String classtype = guessType(prova);
System.out.println(classtype);
}
}

View File

@ -1,350 +0,0 @@
package org.gcube.contentmanagement.lexicalmatcher.analysis.core;
import java.util.ArrayList;
import java.util.HashMap;
import org.gcube.contentmanagement.lexicalmatcher.analysis.guesser.data.CategoryOrderedList;
import org.gcube.contentmanagement.lexicalmatcher.analysis.guesser.data.CategoryScores;
import org.gcube.contentmanagement.lexicalmatcher.analysis.guesser.data.SingleResult;
import org.gcube.contentmanagement.lexicalmatcher.analysis.guesser.treeStructure.chunks.ChunkSet;
import org.gcube.contentmanagement.lexicalmatcher.analysis.guesser.treeStructure.chunks.ReferenceChunk;
import org.gcube.contentmanagement.lexicalmatcher.analysis.guesser.treeStructure.chunks.ReferenceChunkSet;
import org.gcube.contentmanagement.lexicalmatcher.analysis.guesser.treeStructure.chunks.SetOfReferenceChunkSet;
import org.gcube.contentmanagement.lexicalmatcher.analysis.guesser.treeStructure.chunks.SingletonChunkSet;
import org.gcube.contentmanagement.lexicalmatcher.analysis.guesser.treeStructure.chunks.TimeSeriesChunk;
import org.gcube.contentmanagement.lexicalmatcher.analysis.guesser.treeStructure.chunks.TimeSeriesChunkSet;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.contentmanagement.lexicalmatcher.utils.DatabaseFactory;
import org.gcube.contentmanagement.lexicalmatcher.utils.MathFunctions;
import org.hibernate.SessionFactory;
public class Engine {
private String ConfigurationFileNameLocal = "hibernate.cfg.xml";
private SessionFactory referenceDBSession;
public ArrayList<String> bestCategories;
public ArrayList<Double> bestScores;
public ArrayList<String> bestColumns;
public HashMap<String, CategoryScores> scoresTable;
public String columnFilter;
private LexicalEngineConfiguration config;
private TimeSeriesChunk singletonChunk;
public ArrayList<SingleResult> getSingletonMatches(){
return singletonChunk.getDetailedResults();
}
public String getSingletonElement(){
return singletonChunk.getSingletonEntry();
}
public SessionFactory getDBSession() throws Exception {
if (referenceDBSession == null) {
referenceDBSession = DatabaseFactory.initDBConnection(ConfigurationFileNameLocal);
}
return referenceDBSession;
}
public SessionFactory getDBSession(LexicalEngineConfiguration externalConf) throws Exception {
if (referenceDBSession == null) {
referenceDBSession = DatabaseFactory.initDBConnection(ConfigurationFileNameLocal, externalConf);
}
return referenceDBSession;
}
public void resetEngine(LexicalEngineConfiguration Config,String ColumnFilter,String configPath){
config = Config;
scoresTable = new HashMap<String, CategoryScores>();
bestCategories = new ArrayList<String>();
bestColumns = new ArrayList<String>();
bestScores = new ArrayList<Double>();
columnFilter = ColumnFilter;
// ConfigurationFileNameLocal = configPath+"/"+ConfigurationFileNameLocal;
}
public Engine(LexicalEngineConfiguration Config,String ColumnFilter,String configPath) {
config = Config;
scoresTable = new HashMap<String, CategoryScores>();
bestCategories = new ArrayList<String>();
bestColumns = new ArrayList<String>();
bestScores = new ArrayList<Double>();
columnFilter = ColumnFilter;
ConfigurationFileNameLocal = configPath+"/"+ConfigurationFileNameLocal;
}
public void calcLike(CategoryOrderedList col, String unknownSeriesName, String unknownSeriesColumn) {
scoresTable = col.getScoresTable();
// take a time series set of chunks
TimeSeriesChunkSet tsChunkSet = null;
try {
tsChunkSet = new TimeSeriesChunkSet(config.TimeSeriesChunksToTake, config.chunkSize, unknownSeriesName, unknownSeriesColumn,config, this);
} catch (Exception e) {
e.printStackTrace();
AnalysisLogger.getLogger().error("Engine->calcLike-> ERROR could not retrieve time series chunks " + e.getLocalizedMessage());
}
// if we took the ts chunk set correctly perform calculation
if (tsChunkSet != null) {
// generate the set of reference chunks
SetOfReferenceChunkSet setRefChunksSet = new SetOfReferenceChunkSet(col.getOrderedList(),config, this);
TimeSeriesChunk tsChunk = tsChunkSet.nextChunk();
// for all ts chunks
while (tsChunk != null) {
// take a set of chunks from a reference category
ReferenceChunkSet refChunkSet = setRefChunksSet.getNextChunkSet();
while (refChunkSet != null) {
// take a chunk in the reference chunk set
ReferenceChunk refChunk = refChunkSet.nextChunk();
while (refChunk != null) {
try {
tsChunk.compareToReferenceChunk(scoresTable, refChunk);
} catch (Exception e) {
e.printStackTrace();
AnalysisLogger.getLogger().error("Engine->calcLike-> ERROR could not compare time series chunk with reference chunk " + e.getLocalizedMessage());
}
// take another chunk in the reference chunk set
refChunk = refChunkSet.nextChunk();
}
// check score
UpdateScores(refChunkSet.getSeriesName(),false);
// take another set of chunks from another reference category
refChunkSet = setRefChunksSet.getNextChunkSet();
}
tsChunk = tsChunkSet.nextChunk();
}
}
}
boolean threadActivity[];
private void wait4Thread(int index){
// wait until thread is free
while (threadActivity[index]) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
}
private void startNewTCalc(TimeSeriesChunk tsChunk, ReferenceChunkSet refChunkSet,int index){
threadActivity[index] = true;
ThreadCalculator tc = new ThreadCalculator(tsChunk, refChunkSet,index);
Thread t = new Thread(tc);
t.start();
// AnalysisLogger.getLogger().info("ThreadCalculator<-go "+index);
}
public void calcLikeThread(CategoryOrderedList col, String unknownSeriesName, String unknownSeriesColumn,String singletonString) {
scoresTable = col.getScoresTable();
// take a time series set of chunks
ChunkSet tsChunkSet = null;
int[] currentThreads = MathFunctions.generateSequence(config.numberOfThreadsToUse);
int currentThread = 0;
threadActivity = new boolean [currentThreads.length];
//initialize to false;
for (int j=0;j<threadActivity.length;j++){
threadActivity[j] = false;
}
try {
if (singletonString==null)
tsChunkSet = new TimeSeriesChunkSet(config.TimeSeriesChunksToTake, config.chunkSize, unknownSeriesName, unknownSeriesColumn,config, this);
else{
tsChunkSet = new SingletonChunkSet(singletonString,config, this);
}
} catch (Exception e) {
e.printStackTrace();
AnalysisLogger.getLogger().error("Engine->calcLike-> ERROR could not retrieve time series chunks " + e.getLocalizedMessage());
}
// if we took the ts chunk set correctly perform calculation
if (tsChunkSet != null) {
// generate the set of reference chunks
SetOfReferenceChunkSet setRefChunksSet = new SetOfReferenceChunkSet(col.getOrderedList(),config, this);
TimeSeriesChunk tsChunk = (TimeSeriesChunk)tsChunkSet.nextChunk();
AnalysisLogger.getLogger().debug("tsChunk is null "+(tsChunk != null));
// for all ts chunks
while (tsChunk != null) {
// take a set of chunks from a reference category
ReferenceChunkSet refChunkSet = setRefChunksSet.getNextChunkSet();
while (refChunkSet != null) {
wait4Thread(currentThreads[currentThread]);
startNewTCalc(tsChunk, refChunkSet,currentThreads[currentThread]);
// makeComparisonsTSChunk2RefChunks(tsChunk, refChunkSet);
// take another set of chunks from another reference category
refChunkSet = setRefChunksSet.getNextChunkSet();
currentThread++;
if (currentThread >= currentThreads.length)
currentThread = 0;
}
//if the chunk is a singleton, don't process other and record the result
if (tsChunk.isSingleton()){
singletonChunk = tsChunk;
break;
}
tsChunk = (TimeSeriesChunk)tsChunkSet.nextChunk();
}
//wait for last threads to finish
for (int i : currentThreads) {
// free previous calculation
wait4Thread(i);
}
}
}
private void makeComparisonsTSChunk2RefChunks(TimeSeriesChunk tsChunk, ReferenceChunkSet refChunkSet) {
// take a chunk in the reference chunk set
ReferenceChunk refChunk = refChunkSet.nextChunk();
while (refChunk != null) {
try {
tsChunk.compareToReferenceChunk(scoresTable, refChunk,columnFilter);
} catch (Exception e) {
e.printStackTrace();
AnalysisLogger.getLogger().error("Engine->calcLike-> ERROR could not compare time series chunk with reference chunk " + e.getLocalizedMessage());
}
//if the TimeSeries chunk states the processing must be interrupted, don't perform other comparisons
if (tsChunk.mustInterruptProcess())
break;
// take another chunk in the reference chunk set
refChunk = refChunkSet.nextChunk();
}
// check score
UpdateScores(refChunkSet.getSeriesName(),tsChunk.isSingleton());
}
private void UpdateScores(String categoryName, boolean singletonMatch) {
CategoryScores categoryScore = scoresTable.get(categoryName);
ArrayList<String> bestCols = categoryScore.findBestList();
String bestColumn = null;
double score = 0;
if (bestCols.size() > 0) {
bestColumn = bestCols.get(0);
score = categoryScore.getScore(bestColumn,singletonMatch);
}
AnalysisLogger.getLogger().trace("Engine->UpdateScores-> \tBEST SUITABLE COLUMN IS: " + bestColumn);
AnalysisLogger.getLogger().trace("Engine->UpdateScores-> \tBEST SCORE IS: " + score);
// order this column
if (score > config.categoryDiscardThreshold) {
int index = 0;
// insert at the right point in the classification
for (Double dscore : bestScores) {
if (dscore.doubleValue() < score) {
break;
}
index++;
}
bestCategories.add(index, categoryName);
bestScores.add(index, score);
bestColumns.add(index, bestColumn);
checkAndAddColumns(categoryScore, bestCols, categoryName,singletonMatch);
}
}
private void checkAndAddColumns(CategoryScores scores, ArrayList<String> bestCols, String categoryName,boolean singletonMatch) {
int size = bestCols.size();
double bestScore = scores.getScore(bestCols.get(0),singletonMatch);
for (int i = 1; i < size; i++) {
// take the i-th column
String column = bestCols.get(i);
if (column != null) {
// check the score
double score = scores.getScore(column,singletonMatch);
// if the score is near the best, add the column
if ((score > 0) && (score >= (bestScore - 0.5 * bestScore))) {
int index = 0;
// insert at the right point in the classification
for (Double dscore : bestScores) {
if (dscore.doubleValue() < score) {
break;
}
index++;
}
// AnalysisLogger.getLogger().info("chechAndAddColumns -> column to add "+column+" category "+categoryName+" with value "+score+" previous "+(bestScore - 0.5 * bestScore));
bestColumns.add(index,column);
bestScores.add(index,score);
bestCategories.add(index,categoryName);
// AnalysisLogger.getLogger().info("chechAndAddColumns -> "+bestCategories);
}
}
}
}
private class ThreadCalculator implements Runnable {
TimeSeriesChunk tsChunk;
ReferenceChunkSet refChunksSet;
int index;
public ThreadCalculator(TimeSeriesChunk tsChunk, ReferenceChunkSet refChunksSet,int index) {
this.tsChunk = tsChunk;
this.refChunksSet = refChunksSet;
this.index = index;
}
public void run() {
// AnalysisLogger.getLogger().info("ThreadCalculator->started "+index);
makeComparisonsTSChunk2RefChunks(tsChunk, refChunksSet);
threadActivity[index]=false;
// AnalysisLogger.getLogger().info("ThreadCalculator>-finished "+index);
}
}
}

View File

@ -1,322 +0,0 @@
package org.gcube.contentmanagement.lexicalmatcher.analysis.core;
import java.io.FileInputStream;
import java.util.Properties;
public class LexicalEngineConfiguration {
public void configure(String absoluteFilePath) throws Exception {
Properties props = new Properties();
FileInputStream fis = new FileInputStream(absoluteFilePath);
props.load(fis);
categoryDiscardThreshold = Float.parseFloat(props.getProperty("categoryDiscardThreshold"));
entryAcceptanceThreshold = Integer.parseInt(props.getProperty("entryAcceptanceThreshold"));
chunkSize = Integer.parseInt(props.getProperty("chunkSize"));
TimeSeriesChunksToTake = Integer.parseInt(props.getProperty("timeSeriesChunksToTake"));
ReferenceChunksToTake = Integer.parseInt(props.getProperty("referenceChunksToTake"));
randomTake = Boolean.parseBoolean(props.getProperty("randomTake"));
useSimpleDistance = Boolean.parseBoolean(props.getProperty("useSimpleDistance"));
numberOfThreadsToUse = Integer.parseInt(props.getProperty("numberOfThreadsToUse"));
categoryDiscardDifferencialThreshold = Float.parseFloat(props.getProperty("categoryDiscardDifferencialThreshold"));
singleEntryRecognitionMaxDeviation = Float.parseFloat(props.getProperty("singleEntryRecognitionMaxDeviation"));
fis.close();
}
public void setCategoryDiscardThreshold(float categoryDiscardThreshold) {
this.categoryDiscardThreshold = categoryDiscardThreshold;
}
public float getCategoryDiscardThreshold() {
return categoryDiscardThreshold;
}
public void setEntryAcceptanceThreshold(float entryAcceptanceThreshold) {
this.entryAcceptanceThreshold = entryAcceptanceThreshold;
}
public float getEntryAcceptanceThreshold() {
return entryAcceptanceThreshold;
}
public void setCategoryDiscardDifferencialThreshold(float categoryDiscardDifferencialThreshold) {
this.categoryDiscardDifferencialThreshold = categoryDiscardDifferencialThreshold;
}
public float getCategoryDiscardDifferencialThreshold() {
return categoryDiscardDifferencialThreshold;
}
public void setChunkSize(int chunkSize) {
this.chunkSize = chunkSize;
}
public int getChunkSize() {
return chunkSize;
}
public void setRandomTake(boolean randomTake) {
this.randomTake = randomTake;
}
public boolean isRandomTake() {
return randomTake;
}
public void setTimeSeriesChunksToTake(int timeSeriesChunksToTake) {
TimeSeriesChunksToTake = timeSeriesChunksToTake;
}
public int getTimeSeriesChunksToTake() {
return TimeSeriesChunksToTake;
}
public void setReferenceChunksToTake(int referenceChunksToTake) {
ReferenceChunksToTake = referenceChunksToTake;
}
public int getReferenceChunksToTake() {
return ReferenceChunksToTake;
}
public void setUseSimpleDistance(boolean useSimpleDistance) {
this.useSimpleDistance = useSimpleDistance;
}
public boolean isUseSimpleDistance() {
return useSimpleDistance;
}
public void setNumberOfThreadsToUse(int numberOfThreadsToUse) {
this.numberOfThreadsToUse = numberOfThreadsToUse;
}
public int getNumberOfThreadsToUse() {
return numberOfThreadsToUse;
}
public void setSingleEntryRecognitionMaxDeviation(float singleEntryRecognitionMaxDeviation) {
this.singleEntryRecognitionMaxDeviation = singleEntryRecognitionMaxDeviation;
}
public float getSingleEntryRecognitionMaxDeviation() {
return singleEntryRecognitionMaxDeviation;
}
public float categoryDiscardThreshold = -Float.MIN_VALUE;
public float entryAcceptanceThreshold = -Float.MIN_VALUE;
public float categoryDiscardDifferencialThreshold = -Float.MIN_VALUE;
public float singleEntryRecognitionMaxDeviation = -Float.MIN_VALUE;
public int chunkSize = -Integer.MIN_VALUE;
public Boolean randomTake = null;
// if set to -1 all chunks will be analyzed
public int TimeSeriesChunksToTake = -Integer.MIN_VALUE;
public int ReferenceChunksToTake = -Integer.MIN_VALUE;
public Boolean useSimpleDistance = null;
public int numberOfThreadsToUse = -Integer.MIN_VALUE;
//database parameters
public String databaseDriver = null;
public String databaseURL = null;
public String databaseUserName = null;
public String databasePassword = null;
public String databaseDialect = null;
public String databaseIdleConnectionTestPeriod = null;
public String databaseAutomaticTestTable = null;
//reference data parameters
public String referenceTable = null;
public String referenceColumn = null;
public String idColumn= null;
public String nameHuman = null;
public String description = null;
public void mergeConfig(LexicalEngineConfiguration config){
if (config.getCategoryDiscardDifferencialThreshold()!=-Float.MIN_VALUE)
setCategoryDiscardDifferencialThreshold(config.getCategoryDiscardDifferencialThreshold());
if (config.getSingleEntryRecognitionMaxDeviation()!=-Float.MIN_VALUE)
setSingleEntryRecognitionMaxDeviation(config.getSingleEntryRecognitionMaxDeviation());
if (config.getCategoryDiscardThreshold()!=-Float.MIN_VALUE)
setCategoryDiscardThreshold(config.getCategoryDiscardThreshold());
if (config.getChunkSize()!=-Integer.MIN_VALUE)
setChunkSize(config.getChunkSize());
if (config.getEntryAcceptanceThreshold()!=-Float.MIN_VALUE)
setEntryAcceptanceThreshold(config.getEntryAcceptanceThreshold());
if (config.getNumberOfThreadsToUse()!=-Integer.MIN_VALUE)
setNumberOfThreadsToUse(config.getNumberOfThreadsToUse());
if (config.getReferenceChunksToTake()!=-Integer.MIN_VALUE)
setReferenceChunksToTake(config.getReferenceChunksToTake());
if (config.getTimeSeriesChunksToTake()!=-Integer.MIN_VALUE)
setTimeSeriesChunksToTake(config.getTimeSeriesChunksToTake());
if (config.randomTake!= null)
setRandomTake(config.isRandomTake());
if (config.useSimpleDistance!=null)
setUseSimpleDistance(config.isUseSimpleDistance());
//database information merge
if (config.databaseDriver!=null)
setDatabaseDriver(config.databaseDriver);
if (config.databaseDialect!=null)
setDatabaseDialect(config.databaseDialect);
if (config.databaseAutomaticTestTable!=null)
setDatabaseAutomaticTestTable(config.databaseAutomaticTestTable);
if (config.databaseIdleConnectionTestPeriod!=null)
setDatabaseIdleConnectionTestPeriod(config.databaseIdleConnectionTestPeriod);
if (config.databaseUserName!=null)
setDatabaseUserName(config.databaseUserName);
if (config.databasePassword!=null)
setDatabasePassword(config.databasePassword);
if (config.databaseURL!=null)
setDatabaseURL(config.databaseURL);
if (config.referenceTable!=null)
setReferenceTable(config.referenceTable);
if (config.referenceColumn!=null)
setReferenceColumn(config.referenceColumn);
if (config.idColumn!=null)
setIdColumn(config.idColumn);
if (config.nameHuman!=null)
setNameHuman(config.nameHuman);
if (config.description!=null)
setDescription(config.description);
}
public void setDatabaseDriver(String databaseDriver) {
this.databaseDriver = databaseDriver;
}
public String getDatabaseDriver() {
return databaseDriver;
}
public void setDatabaseURL(String databaseURL) {
this.databaseURL = databaseURL;
}
public String getDatabaseURL() {
return databaseURL;
}
public void setDatabaseUserName(String databaseUserName) {
this.databaseUserName = databaseUserName;
}
public String getDatabaseUserName() {
return databaseUserName;
}
public void setDatabasePassword(String databasePassword) {
this.databasePassword = databasePassword;
}
public String getDatabasePassword() {
return databasePassword;
}
public void setDatabaseDialect(String databaseDialect) {
this.databaseDialect = databaseDialect;
}
public String getDatabaseDialect() {
return databaseDialect;
}
public void setDatabaseIdleConnectionTestPeriod(String databaseIdleConnectionTestPeriod) {
this.databaseIdleConnectionTestPeriod = databaseIdleConnectionTestPeriod;
}
public String getDatabaseIdleConnectionTestPeriod() {
return databaseIdleConnectionTestPeriod;
}
public void setDatabaseAutomaticTestTable(String databaseAutomaticTestTable) {
this.databaseAutomaticTestTable = databaseAutomaticTestTable;
}
public String getDatabaseAutomaticTestTable() {
return databaseAutomaticTestTable;
}
public String getReferenceTable() {
return referenceTable;
}
public void setReferenceTable(String referenceTable) {
this.referenceTable = referenceTable;
}
public String getReferenceColumn() {
return referenceColumn;
}
public void setReferenceColumn(String referenceColumn) {
this.referenceColumn = referenceColumn;
}
public String getIdColumn() {
return idColumn;
}
public void setIdColumn(String idColumn) {
this.idColumn = idColumn;
}
public String getNameHuman() {
return nameHuman;
}
public void setNameHuman(String nameHuman) {
this.nameHuman = nameHuman;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

View File

@ -1,32 +0,0 @@
package org.gcube.contentmanagement.lexicalmatcher.analysis.examples;
import org.gcube.contentmanagement.lexicalmatcher.analysis.run.CategoryGuesser;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
public class Example1_Species {
public static void main(String[] args) {
try {
int attempts = 1;
String configPath = ".";
CategoryGuesser guesser = new CategoryGuesser(configPath);
//bench 1
AnalysisLogger.getLogger().warn("----------------------BENCH 1-------------------------");
String seriesName = "import_2c97f580_35a0_11df_b8b3_aa10916debe6";
String column = "field1";
String correctFamily = "SPECIES";
String correctColumn = "SCIENTIFIC_NAME";
CategoryGuesser.AccuracyCalc(guesser, configPath, seriesName, column, attempts, correctFamily, correctColumn);
AnalysisLogger.getLogger().warn("--------------------END BENCH 1-----------------------\n");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,32 +0,0 @@
package org.gcube.contentmanagement.lexicalmatcher.analysis.examples;
import org.gcube.contentmanagement.lexicalmatcher.analysis.run.CategoryGuesser;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
public class Example2_Area {
public static void main(String[] args) {
try {
int attempts = 1;
String configPath = ".";
CategoryGuesser guesser = new CategoryGuesser(configPath);
//bench 1
AnalysisLogger.getLogger().warn("----------------------BENCH 1-------------------------");
String seriesName = "import_2c97f580_35a0_11df_b8b3_aa10916debe6";
String column = "field3";
String correctFamily = "AREA";
String correctColumn = "NAME_EN";
CategoryGuesser.AccuracyCalc(guesser, configPath, seriesName, column, attempts, correctFamily, correctColumn);
AnalysisLogger.getLogger().warn("--------------------END BENCH 1-----------------------\n");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Some files were not shown because too many files have changed in this diff Show More