Compare commits

..

No commits in common. "master" and "7a4acb5bb6efd93905b5acab1304502945660a47" have entirely different histories.

14 changed files with 179 additions and 75 deletions

View File

@ -1,8 +1,8 @@
module.exports = {
map_builder: require('./svgmap/svg-map-builder'),
style_adaptor: require('./svgmap/helpers/style-adaptor'),
svg_nodes: require('./svgmap/drawers/svg-nodes'),
MapBuilder: require('./svgmap/svg-map-builder'),
MapSaver: require('./svgmap/svg-map-saver'),
BBox: require('./libs/bbox'),
StyleAdaptor: require('./svgmap/helpers/style-adaptor'),
SvgNode: require('./svgmap/svg-node'),
SvgNodes: require('./svgmap/drawers/svg-nodes'),
}

View File

@ -71,22 +71,6 @@ class BBox {
clone(){
return BBox.fromLTRB(this.l, this.t, this.r, this.b)
}
expand(dx, dy){
dy = dy === null ? dx : dy
console.log(dx, dy)
this.l -= dx
this.r += dx
this.t -= dy
this.b += dy
return this
}
expandPerc(perc){
const w = this.w() * perc / 100
const h = this.h() * perc / 100
return this.expand(w, h)
}
}
module.exports = BBox

View File

@ -1,5 +1,5 @@
class Transfrom {
static fromCoordSystems(cs1, cs2){
static fromCoordSyses(cs1, cs2){
let tr = new Transfrom()
tr.cs1 = cs1

View File

@ -1,5 +1,5 @@
{
"name": "@timal/app_mapbuilder",
"name": "app_mapbuilder",
"version": "1.0.0",
"description": "Svg map builder tools",
"main": "index.js",
@ -8,15 +8,9 @@
},
"repository": {
"type": "git",
"url": "http://git.db.timal.kz/djerom/app_mapbuilder.git"
"url": "http://git.dev.aurora.hub01.site/djerom/app_mapbuilder.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"directories": {
"test": "test"
},
"publishConfig": {
"registry": "https://npm.db.timal.kz/"
}
"license": "ISC"
}

26
services/map.js Normal file
View File

@ -0,0 +1,26 @@
module.exports = class {
set_scale(scale){
this.scale = scale
}
get_bbox(data){
return data.reduce(
(s, c) => ({
l: Math.min(s.l, c.x),
t: Math.min(s.t, c.y),
r: Math.max(s.r, c.x),
b: Math.max(s.b, c.y),
}),
{ l: data[0].x, t: data[0].y, r: data[0].x, b: data[0].y }
)
}
wells_layer(wells){
}
render(){
}
}

116
services/sql/prod_inj.js Normal file
View File

@ -0,0 +1,116 @@
export default {
max_date(){
return `SELECT MAX(date(year||'-01-01', (month - 1)||' month')) as date FROM production_injections`
},
devobjs(){
return `SELECT distinct(object) as devobj FROM production_injections`
},
totals(devobj){
return `SELECT
wells.well, wells.whx, wells.why
,SUM(production_injections.woptm) as wopt
,SUM(production_injections.wwptm) as wwpt
,SUM(production_injections.wsgptv) as wgpt
,SUM(production_injections.wwitv) as wwit
,SUM(production_injections.days) as days
,SUM(production_injections.wwptm)+SUM(production_injections.woptm) as wlpt
,SUM(production_injections.wwptm)/(SUM(production_injections.wwptm)+SUM(production_injections.woptm)) as wlf
FROM
wells, production_injections
WHERE
wells.well=production_injections.well
AND production_injections.object='${devobj}'
GROUP BY
wells.well
ORDER BY
wlpt DESC, wwit DESC`
},
rates(devobj, date){
date = new Date(date)
const year_month = date.getFullYear()*100 + date.getMonth()
return `SELECT
wells.well, wells.whx, wells.why
,SUM(production_injections.woptm)/SUM(production_injections.days) as wopr
,SUM(production_injections.wwptm)/SUM(production_injections.days) as wwpr
,SUM(production_injections.wsgptv)/SUM(production_injections.days) as wgpr
,SUM(production_injections.wwitv)/SUM(production_injections.days) as wwir
,SUM(production_injections.days) as days
,(SUM(production_injections.wwptm)+SUM(production_injections.woptm)) / SUM(production_injections.days) as wlpr
,SUM(production_injections.wwptm)/(SUM(production_injections.wwptm)+SUM(production_injections.woptm)) as wlf
FROM
wells, production_injections
WHERE
wells.well=production_injections.well
AND production_injections.object='${devobj}'
AND (year*100+month)=${year_month}
GROUP BY
wells.well`
},
production_injection(field, devobj, date){
const f_date = date ? `AND year*1000+month=${date.getFullYear()*1000+date.getMonth()}` : ''
console.log(f_date)
return `SELECT
wells.well, wells.whx, wells.why
,SUM(production_injections.woptm) as wopt
,SUM(production_injections.wwptm) as wwpt
,SUM(production_injections.wsgptv) as wgpt
,SUM(production_injections.wwitv) as wwit
,SUM(production_injections.days) as days
,SUM(production_injections.wwptm)+SUM(production_injections.woptm) as wlpt
,SUM(production_injections.wwptm)/(SUM(production_injections.wwptm)+SUM(production_injections.woptm)) as wlf
FROM
wells, production_injections
WHERE
AND wells.well=production_injections.well
AND production_injections.object='${devobj}'
AND (year*1000+month)=${max_year_month}
GROUP BY
wells.well`
},
production_total(field, devobj){
return `SELECT
wells.well, wells.whx, wells.why
,SUM(production_injections.woptm) as wopt
,SUM(production_injections.wwptm) as wwpt
,SUM(production_injections.wsgptv) as wgpt
,SUM(production_injections.wwitv) as wwit
,SUM(production_injections.wwptm)+SUM(production_injections.woptm) as wlpt
,SUM(production_injections.wwptm)/(SUM(production_injections.wwptm)+SUM(production_injections.woptm)) as wlf
FROM
wells, production_injections
WHERE
wells.well=production_injections.well
AND object='${devobj}'
GROUP BY
wells.well`
},
injection_total(){
const query_all = `SELECT
wells.well, wells.whx, wells.why
,SUM(production_injections.woptm) as wopt
,SUM(production_injections.wwptm) as wwpt
,SUM(production_injections.wsgptv) as wgpt
,SUM(production_injections.wwitv) as wwit
,SUM(production_injections.wwptm)+SUM(production_injections.woptm) as wlpt
,SUM(production_injections.wwptm)/(SUM(production_injections.wwptm)+SUM(production_injections.woptm)) as wlf
FROM
wells, production_injections
WHERE
wells.well=production_injections.well
AND object='${devobj}'
GROUP BY
wells.well
HAVING
wwit>0
`
}
}

9
services/wells.js Normal file
View File

@ -0,0 +1,9 @@
module.exports = class {
constructor(url){
this.url = url
}
get_wells(){
}
}

View File

@ -1,3 +1,3 @@
const SvgNodes = require("./svg-nodes");
module.exports = (name) => SvgNodes.group([`<metadata id="CorelCorpID_${name}Corel-Layer"/>`]).set_attr("id", name);
module.exports = (name) => SvgNodes.group(['<metadata id="CorelCorpID_WWPTCorel-Layer"/>']).set_attr("id", name);

View File

@ -94,7 +94,7 @@ function ring_sectors(r0, r1, sectors) {
function text(text) {
let node = new SvgNode("text");
node.items = text ? [text] : [];
node.items = [text];
node.set_attrs({ x: 0, y: 0 });
return node;
}
@ -117,10 +117,6 @@ const defs = {
},
};
function corel_layer(name) {
return new SvgNode('g', null, [`<metadata id="CorelCorpID_${name}Corel-Layer"/>`]).set_attr("id", name)
}
module.exports = {
node,
svg,
@ -133,7 +129,6 @@ module.exports = {
ring_sector,
ring_sectors,
text,
corel_layer
};
module.exports.default = module.exports;

View File

@ -8,7 +8,7 @@ function pt(wopt, wwpt, rmm, ppu, style) {
}
function it(rmm, ppu, style) {
return SvgNodes.circle(rmm * ppu).add_style(style);
return SvgNodes.circle(rmm * ppu).add_style(style.wit);
}
module.exports = {

0
svgmap/index.js Normal file
View File

View File

@ -1,20 +1,9 @@
const SvgNode = require("./svg-node.js");
const SvgNodes = require("./drawers/svg-nodes.js");
const Defs = require('./helpers/style-defs')
const well_ring = require('./drawers/well-ring')
const well_head = require('./drawers/well-head')
const corel_layer = require('./drawers/corel-layer')
const BBox = require('../libs/bbox')
const SvgNode = require('./svg-node')
const svg_nodes = require('./drawers/svg-nodes')
function get_bbox(data, min_size = 1000) {
let bbox = BBox.from_array(data)
if (bbox.w() == 0 || bbox.h() == 0) {
bbox.r += min_size;
bbox.b += min_size;
}
return bbox;
}
function build_pt_layer(wells, settings, style) {
function t2r(tons) {
@ -24,22 +13,19 @@ function build_pt_layer(wells, settings, style) {
let { ppu } = settings;
const wells_layer = corel_layer("wells");
const rings_layer = corel_layer("rings");
let svg = corel_layer("WWPT");
// Круги
rings_layer.append(wells.map((x) => well_ring.pt(x.wopt, x.wwpt, t2r(x.wlpt), ppu, style).move(x.lx, x.ly)));
svg.append(wells.map((x) => well_ring.pt(x.wopt, x.wwpt, t2r(x.wlpt), ppu, style).move(x.lx, x.ly)));
// Знак скважины
wells_layer.append(
svg.append(
wells.map((x) => well_head[t2r(x.wlpt) > 1.6 ? "prod" : "gray"](ppu, style).move(x.lx, x.ly))
);
// Имя скважины
wells_layer.append(wells.map((x) => well_head.name(x.name, ppu, style).move(x.lx, x.ly)));
svg.append(wells.map((x) => well_head.name(x.name, ppu, style).move(x.lx, x.ly)));
// Обводненность
wells_layer.append(wells.map((x) => well_head.wlp(x.wlf, ppu, style).move(x.lx, x.ly)));
let svg = svg_nodes.container([rings_layer, wells_layer])
svg.append(wells.map((x) => well_head.wlp(x.wlf, ppu, style).move(x.lx, x.ly)));
return { svg };
}
@ -52,28 +38,23 @@ function build_it_layer(wells, settings, style) {
let { ppu } = settings;
const wells_layer = corel_layer("wells");
const rings_layer = corel_layer("rings");
let svg = corel_layer("WWIT");
// Круги
rings_layer.append(wells.map((x) => well_ring.it(t2r(x.wwit), ppu, style.wit).move(x.lx, x.ly)));
rings_layer.append(wells.map((x) => well_ring.it(t2r(x.wsit), ppu, style.sit).move(x.lx, x.ly)));
svg.append(wells.map((x) => well_ring.it(t2r(x.wwit), ppu, style).move(x.lx, x.ly)));
// Знак скважины
wells_layer.append(
svg.append(
wells.map((x) => well_head[t2r(x.wwit) > 1.6 ? "inj" : "gray"](ppu, style).move(x.lx, x.ly))
);
// Имя скважины
wells_layer.append(wells.map((x) => well_head.name(x.name, ppu, style).move(x.lx, x.ly)));
let svg = svg_nodes.container([rings_layer, wells_layer])
svg.append(wells.map((x) => well_head.name(x.name, ppu, style).move(x.lx, x.ly)));
return { svg };
}
module.exports = {
get_bbox,
build_pt_layer,
build_it_layer,
};

View File

@ -16,7 +16,7 @@ module.exports = class SvgSaver {
const csh = Math.abs(cs_mm.y1 - cs_mm.y0);
const bbox_ppu = BBox.fromLTRB(cs_ppu.x0, cs_ppu.y0, cs_ppu.x1, cs_ppu.y1);
this.tr = transfrom.fromCoordSystems(cs1, cs_ppu);
this.tr = transfrom.fromCoordSyses(cs1, cs_ppu);
this.settings = settings
this.style = adaptor.update_styles(style, settings.ppu);
@ -35,12 +35,10 @@ module.exports = class SvgSaver {
}
append_defs(defs) {
if (!defs) return
this.svg.append(defs);
}
append_svg(svg) {
if (!svg) return
this.svg.append(svg);
}

View File

@ -6,7 +6,7 @@ class SvgNode {
}
append(...items){
this.items = [...this.items, ...items.filter(x => x)]
this.items.push(...items)
return this
}
@ -46,18 +46,19 @@ class SvgNode {
// console.log(typeof node)
// if (typeof node == 'undefined') return ''
if (typeof node == 'string') return node
else if (typeof node == 'object' && node.render) return node.render()
else if (typeof node == 'object' && node.tag) return node.render()
else if (Array.isArray(node)) return node.map(this._render_node).join('')
else return ''
}
render() {
let attrs = Object.keys(this.attrs).map(x => ` ${x}="${this.attrs[x]}"`).join('')
let attrs = Object.keys(this.attrs).filter(x => this.attrs[x]).map(x => ` ${x}="${this.attrs[x]}"`).join('')
// console.log(this.style ? Object.keys(this.style).map(x => `${x}:${this.style[x]}`) : '')
let style = this.style ? ' style="' + Object.keys(this.style).map(x => `${x}:${this.style[x]}`).join('; ') + '"' : ''
let transfrom = this.transform ? ` transform="translate(${this.transform.x},${this.transform.y})"` : ''
let items = this.items ? Array.isArray(this.items) ? this.items.map(x => this._render_node(x)).join('') : this._render_node(this.items) : ''
let items = this.items ? this.items.map(x => this._render_node(x)).join('') : ''
// console.log('this.items', this.items, items)
if (this.tag)
return `<${this.tag}${attrs}${style}${transfrom}>${items}</${this.tag}>`
else