Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
blendb
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
23
Issues
23
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
C3SL
blendb
Commits
ea6ddc63
Commit
ea6ddc63
authored
Jul 31, 2018
by
Lucas Fernandes de Oliveira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue/80' into 'develop'
Issue
#80
: Add enumHandler See merge request
!70
parents
6f4d8d18
e7b3f0bd
Pipeline
#16930
passed with stages
in 54 seconds
Changes
8
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
174 additions
and
147 deletions
+174
-147
collect.ts
src/api/controllers/collect.ts
+3
-2
dimension.ts
src/core/dimension.ts
+4
-38
enumType.ts
src/core/enumType.ts
+0
-45
metric.ts
src/core/metric.ts
+3
-45
source.ts
src/core/source.ts
+4
-4
configParser.spec.ts
src/util/configParser.spec.ts
+2
-2
configParser.ts
src/util/configParser.ts
+11
-11
enumHandler.ts
src/util/enumHandler.ts
+147
-0
No files found.
src/api/controllers/collect.ts
View file @
ea6ddc63
...
...
@@ -23,6 +23,7 @@ import { Request } from "../types";
import
{
Source
,
Field
}
from
"
../../core/source
"
;
import
{
EnumType
}
from
"
../../core/enumType
"
;
import
{
DataType
}
from
"
../../common/types
"
;
import
{
EnumHandler
}
from
"
../../util/enumHandler
"
;
/**
* Dictionary indexed by a type name which return a
...
...
@@ -133,10 +134,10 @@ export class CollectCtrl {
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
){
if
(
fields
[
i
].
dataType
!==
DataType
.
NONE
){
if
(
!
validador
[
Enum
Type
.
stringfyDataType
(
fields
[
i
].
dataType
)](
data
[
i
])
===
true
){
if
(
!
validador
[
Enum
Handler
.
stringfyDataType
(
fields
[
i
].
dataType
)](
data
[
i
])
===
true
){
throw
new
Error
(
"
The value '
"
+
data
[
i
]
+
"
' from '
"
+
fields
[
i
].
name
+
"
' isn't a type
"
+
[
Enum
Type
.
stringfyDataType
(
fields
[
i
].
dataType
)]);
"
' isn't a type
"
+
[
Enum
Handler
.
stringfyDataType
(
fields
[
i
].
dataType
)]);
}
}
...
...
src/core/dimension.ts
View file @
ea6ddc63
...
...
@@ -19,7 +19,7 @@
*/
import
{
RelationType
,
DataType
}
from
"
../common/types
"
;
import
{
Enum
Type
}
from
"
./enumType
"
;
import
{
Enum
Handler
}
from
"
../util/enumHandler
"
;
/** Parameters used to create a Dimension object. */
export
interface
DimensionOptions
{
...
...
@@ -96,52 +96,18 @@ export class Dimension {
if
(
this
.
relation
===
RelationType
.
NONE
)
{
return
{
name
:
this
.
name
,
dataType
:
(
this
.
dataType
!==
DataType
.
NONE
)
?
Enum
Type
.
stringfyDataType
(
this
.
dataType
)
:
this
.
enumType
,
dataType
:
(
this
.
dataType
!==
DataType
.
NONE
)
?
Enum
Handler
.
stringfyDataType
(
this
.
dataType
)
:
this
.
enumType
,
description
:
this
.
description
};
}
else
{
return
{
name
:
this
.
name
,
dataType
:
(
this
.
dataType
!==
DataType
.
NONE
)
?
Enum
Type
.
stringfyDataType
(
this
.
dataType
)
:
this
.
enumType
,
dataType
:
(
this
.
dataType
!==
DataType
.
NONE
)
?
Enum
Handler
.
stringfyDataType
(
this
.
dataType
)
:
this
.
enumType
,
parent
:
this
.
parent
.
name
,
relation
:
Dimension
.
stringifyRelationType
(
this
.
relation
),
relation
:
EnumHandler
.
stringifyRelationType
(
this
.
relation
),
description
:
this
.
description
};
}
}
/**
* Parse a string to enum(Relation Type).
* @param r - Relation in string format.
*/
public
static
parseRelationType
(
r
:
string
):
RelationType
{
switch
(
r
)
{
case
"
day
"
:
return
RelationType
.
DAY
;
case
"
month
"
:
return
RelationType
.
MONTH
;
case
"
year
"
:
return
RelationType
.
YEAR
;
default
:
return
RelationType
.
NONE
;
}
}
/**
* Parse an enum(Relation Type) to string.
* @param r - Relation to be stringified.
*/
public
static
stringifyRelationType
(
r
:
RelationType
):
string
{
switch
(
r
)
{
case
RelationType
.
DAY
:
return
"
day
"
;
case
RelationType
.
MONTH
:
return
"
month
"
;
case
RelationType
.
YEAR
:
return
"
year
"
;
default
:
return
""
;
}
}
}
src/core/enumType.ts
View file @
ea6ddc63
...
...
@@ -18,8 +18,6 @@
* along with blend. If not, see <http://www.gnu.org/licenses/>.
*/
import
{
DataType
}
from
"
../common/types
"
;
/** Parameters used to create a Enumerable type object. */
export
interface
EnumTypeOptions
{
/** The type name. */
...
...
@@ -56,47 +54,4 @@ export class EnumType {
values
:
this
.
values
};
}
/**
* Parse an enum(Data type) to string.
* @param a - Data type to be stringified.
*/
public
static
stringfyDataType
(
a
:
DataType
):
string
{
switch
(
a
)
{
case
DataType
.
INTEGER
:
return
"
integer
"
;
case
DataType
.
FLOAT
:
return
"
float
"
;
case
DataType
.
STRING
:
return
"
string
"
;
case
DataType
.
DATE
:
return
"
date
"
;
case
DataType
.
BOOLEAN
:
return
"
boolean
"
;
default
:
return
""
;
}
}
/**
* Parse a string to enum(Data Type).
* @param str - Data type in string format.
*/
public
static
parseDataType
(
str
:
string
):
DataType
{
str
=
str
.
toLocaleLowerCase
();
switch
(
str
)
{
case
"
integer
"
:
return
DataType
.
INTEGER
;
case
"
float
"
:
return
DataType
.
FLOAT
;
case
"
string
"
:
return
DataType
.
STRING
;
case
"
date
"
:
return
DataType
.
DATE
;
case
"
boolean
"
:
return
DataType
.
BOOLEAN
;
default
:
return
DataType
.
NONE
;
}
}
}
src/core/metric.ts
View file @
ea6ddc63
...
...
@@ -19,7 +19,7 @@
*/
import
{
AggregationType
,
DataType
}
from
"
../common/types
"
;
import
{
Enum
Type
}
from
"
./enumType
"
;
import
{
Enum
Handler
}
from
"
../util/enumHandler
"
;
/** Parameters used to create a metric object. */
export
interface
MetricOptions
{
...
...
@@ -83,51 +83,9 @@ export class Metric {
public
strOptions
():
MetricStrOptions
{
return
{
name
:
this
.
name
,
aggregation
:
Metric
.
stringifyAggrType
(
this
.
aggregation
),
dataType
:
Enum
Type
.
stringfyDataType
(
this
.
dataType
),
aggregation
:
EnumHandler
.
stringifyAggrType
(
this
.
aggregation
),
dataType
:
Enum
Handler
.
stringfyDataType
(
this
.
dataType
),
description
:
this
.
description
};
}
/**
* Parse an enum(Aggregation Type) to string.
* @param a - Aggregation function to be stringified.
*/
public
static
stringifyAggrType
(
a
:
AggregationType
):
string
{
switch
(
a
)
{
case
AggregationType
.
SUM
:
return
"
sum
"
;
case
AggregationType
.
AVG
:
return
"
avg
"
;
case
AggregationType
.
COUNT
:
return
"
count
"
;
case
AggregationType
.
MAX
:
return
"
max
"
;
case
AggregationType
.
MIN
:
return
"
min
"
;
default
:
return
""
;
}
}
/**
* Parse a string to enum(Aggregation Type).
* @param str - Aggregation function in string format.
*/
public
static
parseAggrType
(
str
:
string
):
AggregationType
{
switch
(
str
)
{
case
"
sum
"
:
return
AggregationType
.
SUM
;
case
"
avg
"
:
return
AggregationType
.
AVG
;
case
"
count
"
:
return
AggregationType
.
COUNT
;
case
"
min
"
:
return
AggregationType
.
MIN
;
case
"
max
"
:
return
AggregationType
.
MAX
;
default
:
return
AggregationType
.
NONE
;
}
}
}
src/core/source.ts
View file @
ea6ddc63
...
...
@@ -18,8 +18,8 @@
* along with blendb. If not, see <http://www.gnu.org/licenses/>.
*/
import
{
EnumType
}
from
"
./enumType
"
;
import
{
DataType
}
from
"
../common/types
"
;
import
{
EnumHandler
}
from
"
../util/enumHandler
"
;
/** Attribute of a source. */
export
interface
Field
{
...
...
@@ -121,7 +121,7 @@ export class Source {
return
{
name
:
i
.
name
,
description
:
i
.
description
,
dataType
:
(
i
.
dataType
!==
DataType
.
NONE
)
?
Enum
Type
.
stringfyDataType
(
i
.
dataType
)
:
i
.
enumType
dataType
:
(
i
.
dataType
!==
DataType
.
NONE
)
?
Enum
Handler
.
stringfyDataType
(
i
.
dataType
)
:
i
.
enumType
};
});
return
str
;
...
...
@@ -137,8 +137,8 @@ export class Source {
return
{
name
:
i
.
name
,
description
:
i
.
description
,
dataType
:
Enum
Type
.
parseDataType
(
i
.
dataType
),
enumType
:
(
Enum
Type
.
parseDataType
(
i
.
dataType
)
===
DataType
.
NONE
)
?
i
.
dataType
:
""
dataType
:
Enum
Handler
.
parseDataType
(
i
.
dataType
),
enumType
:
(
Enum
Handler
.
parseDataType
(
i
.
dataType
)
===
DataType
.
NONE
)
?
i
.
dataType
:
""
};
});
return
str
;
...
...
src/util/configParser.spec.ts
View file @
ea6ddc63
...
...
@@ -19,11 +19,11 @@
*/
import
{
expect
}
from
"
chai
"
;
import
{
ConfigParser
,
ViewParsingOptions
}
from
"
./configParser
"
;
import
{
Dimension
,
DimensionStrOptions
}
from
"
../core/dimension
"
;
import
{
RelationType
,
DataType
}
from
"
../common/types
"
;
import
{
EnumType
}
from
"
../core/enumType
"
;
import
{
EnumHandler
}
from
"
../util/enumHandler
"
;
import
{
MetricStrOptions
}
from
"
../core/metric
"
;
import
{
SourceStrOptions
}
from
"
../core/source
"
;
...
...
@@ -198,7 +198,7 @@ describe("configParser utility library", () => {
for
(
let
i
=
0
;
i
<
opts
.
length
;
++
i
)
{
let
parsed
=
ConfigParser
.
parseDimOpts
(
opts
[
i
],
dims
,
null
);
expect
(
parsed
.
name
).
to
.
be
.
equal
(
opts
[
i
].
name
);
expect
(
Enum
Type
.
stringfyDataType
(
parsed
.
dataType
)).
to
.
be
.
equal
(
opts
[
i
].
dataType
);
expect
(
Enum
Handler
.
stringfyDataType
(
parsed
.
dataType
)).
to
.
be
.
equal
(
opts
[
i
].
dataType
);
expect
(
parsed
.
parent
).
to
.
be
.
equal
(
dims
[
1
]);
expect
(
parsed
.
relation
).
to
.
be
.
equal
(
strToRelationType
(
opts
[
i
].
relation
));
}
...
...
src/util/configParser.ts
View file @
ea6ddc63
...
...
@@ -30,6 +30,7 @@ import { Source, SourceOptions, SourceStrOptions} from "../core/source";
import
{
Tsort
,
TsortDep
}
from
"
./tsort
"
;
import
*
as
fs
from
"
fs
"
;
import
*
as
yaml
from
"
js-yaml
"
;
import
{
EnumHandler
}
from
"
./enumHandler
"
;
/**
* Parameters used to define view object in the configuration file.
...
...
@@ -319,7 +320,7 @@ export class ConfigParser {
* @param map - Enumerable types available.
*/
public
static
parseDimOpts
(
opts
:
DimensionStrOptions
,
dims
:
Dimension
[],
map
:
EnumTypeMap
):
DimensionOptions
{
let
type
=
Enum
Type
.
parseDataType
(
opts
.
dataType
);
let
type
=
Enum
Handler
.
parseDataType
(
opts
.
dataType
);
if
(
type
===
DataType
.
NONE
)
{
if
(
!
(
map
[
opts
.
dataType
]))
{
throw
new
Error
(
"
[Parsing error] DataType: '
"
+
opts
.
dataType
+
"
' does not exist on Dimension
"
);
...
...
@@ -330,11 +331,11 @@ export class ConfigParser {
if
(
dims
[
i
].
name
===
opts
.
parent
)
{
return
{
name
:
opts
.
name
,
dataType
:
Enum
Type
.
parseDataType
(
opts
.
dataType
),
dataType
:
Enum
Handler
.
parseDataType
(
opts
.
dataType
),
description
:
opts
.
description
,
parent
:
dims
[
i
],
relation
:
Dimension
.
parseRelationType
(
opts
.
relation
),
enumType
:
(
Enum
Type
.
parseDataType
(
opts
.
dataType
)
===
DataType
.
NONE
)
?
opts
.
dataType
:
""
relation
:
EnumHandler
.
parseRelationType
(
opts
.
relation
),
enumType
:
(
Enum
Handler
.
parseDataType
(
opts
.
dataType
)
===
DataType
.
NONE
)
?
opts
.
dataType
:
""
};
}
}
...
...
@@ -343,11 +344,11 @@ export class ConfigParser {
}
return
{
name
:
opts
.
name
,
dataType
:
Enum
Type
.
parseDataType
(
opts
.
dataType
),
dataType
:
Enum
Handler
.
parseDataType
(
opts
.
dataType
),
description
:
opts
.
description
,
parent
:
null
,
relation
:
RelationType
.
NONE
,
enumType
:
(
Enum
Type
.
parseDataType
(
opts
.
dataType
)
===
DataType
.
NONE
)
?
opts
.
dataType
:
""
enumType
:
(
Enum
Handler
.
parseDataType
(
opts
.
dataType
)
===
DataType
.
NONE
)
?
opts
.
dataType
:
""
};
}
...
...
@@ -356,7 +357,7 @@ export class ConfigParser {
* @param opts - Metric struct in configuration file.
*/
public
static
parseMetOpts
(
opts
:
MetricStrOptions
):
MetricOptions
{
let
type
=
Enum
Type
.
parseDataType
(
opts
.
dataType
);
let
type
=
Enum
Handler
.
parseDataType
(
opts
.
dataType
);
if
(
!
(
type
===
DataType
.
FLOAT
||
type
===
DataType
.
INTEGER
)){
throw
new
Error
(
"
[Parsing error] DataType: '
"
+
opts
.
dataType
+
"
' does not exist on Metric
"
);
...
...
@@ -364,8 +365,8 @@ export class ConfigParser {
}
return
{
name
:
opts
.
name
,
aggregation
:
Metric
.
parseAggrType
(
opts
.
aggregation
),
dataType
:
Enum
Type
.
parseDataType
(
opts
.
dataType
),
aggregation
:
EnumHandler
.
parseAggrType
(
opts
.
aggregation
),
dataType
:
Enum
Handler
.
parseDataType
(
opts
.
dataType
),
description
:
opts
.
description
};
}
...
...
@@ -398,7 +399,7 @@ export class ConfigParser {
*/
public
static
parseSourceOpts
(
opts
:
SourceStrOptions
,
map
:
EnumTypeMap
):
SourceOptions
{
for
(
let
k
=
0
;
k
<
opts
.
fields
.
length
;
k
++
)
{
let
type
=
Enum
Type
.
parseDataType
(
opts
.
fields
[
k
].
dataType
);
let
type
=
Enum
Handler
.
parseDataType
(
opts
.
fields
[
k
].
dataType
);
if
(
type
===
DataType
.
NONE
)
{
if
(
!
(
map
[
opts
.
fields
[
k
].
dataType
])){
...
...
@@ -441,5 +442,4 @@ export class ConfigParser {
value
:
strFilter
.
value
});
}
}
src/util/enumHandler.ts
0 → 100644
View file @
ea6ddc63
/*
* Copyright (C) 2018 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana
*
* This file is part of blendb.
*
* blendb is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* blendb 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with blendb. If not, see <http://www.gnu.org/licenses/>.
*/
import
{
RelationType
,
DataType
,
AggregationType
}
from
"
../common/types
"
;
/**
* Enum's handler. Manage parse through the project.
*/
export
class
EnumHandler
{
/**
* Parse an enum(Data type) to string.
* @param a - Data type to be stringified.
*/
public
static
stringfyDataType
(
a
:
DataType
):
string
{
switch
(
a
)
{
case
DataType
.
INTEGER
:
return
"
integer
"
;
case
DataType
.
FLOAT
:
return
"
float
"
;
case
DataType
.
STRING
:
return
"
string
"
;
case
DataType
.
DATE
:
return
"
date
"
;
case
DataType
.
BOOLEAN
:
return
"
boolean
"
;
default
:
return
""
;
}
}
/**
* Parse a string to enum(Data Type).
* @param str - Data type in string format.
*/
public
static
parseDataType
(
str
:
string
):
DataType
{
str
=
str
.
toLocaleLowerCase
();
switch
(
str
)
{
case
"
integer
"
:
return
DataType
.
INTEGER
;
case
"
float
"
:
return
DataType
.
FLOAT
;
case
"
string
"
:
return
DataType
.
STRING
;
case
"
date
"
:
return
DataType
.
DATE
;
case
"
boolean
"
:
return
DataType
.
BOOLEAN
;
default
:
return
DataType
.
NONE
;
}
}
/**
* Parse a string to enum(Relation Type).
* @param r - Relation in string format.
*/
public
static
parseRelationType
(
r
:
string
):
RelationType
{
switch
(
r
)
{
case
"
day
"
:
return
RelationType
.
DAY
;
case
"
month
"
:
return
RelationType
.
MONTH
;
case
"
year
"
:
return
RelationType
.
YEAR
;
default
:
return
RelationType
.
NONE
;
}
}
/**
* Parse an enum(Relation Type) to string.
* @param r - Relation to be stringified.
*/
public
static
stringifyRelationType
(
r
:
RelationType
):
string
{
switch
(
r
)
{
case
RelationType
.
DAY
:
return
"
day
"
;
case
RelationType
.
MONTH
:
return
"
month
"
;
case
RelationType
.
YEAR
:
return
"
year
"
;
default
:
return
""
;
}
}
/**
* Parse an enum(Aggregation Type) to string.
* @param a - Aggregation function to be stringified.
*/
public
static
stringifyAggrType
(
a
:
AggregationType
):
string
{
switch
(
a
)
{
case
AggregationType
.
SUM
:
return
"
sum
"
;
case
AggregationType
.
AVG
:
return
"
avg
"
;
case
AggregationType
.
COUNT
:
return
"
count
"
;
case
AggregationType
.
MAX
:
return
"
max
"
;
case
AggregationType
.
MIN
:
return
"
min
"
;
default
:
return
""
;
}
}
/**
* Parse a string to enum(Aggregation Type).
* @param str - Aggregation function in string format.
*/
public
static
parseAggrType
(
str
:
string
):
AggregationType
{
switch
(
str
)
{
case
"
sum
"
:
return
AggregationType
.
SUM
;
case
"
avg
"
:
return
AggregationType
.
AVG
;
case
"
count
"
:
return
AggregationType
.
COUNT
;
case
"
min
"
:
return
AggregationType
.
MIN
;
case
"
max
"
:
return
AggregationType
.
MAX
;
default
:
return
AggregationType
.
NONE
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment