当前位置:网站首页>时序图数据建模与产业链分析
时序图数据建模与产业链分析
2022-07-04 14:54:00 【马超的博客】
使用图数据分析产业链时序数据- 数据模型的设计
- 函数与过程功能介绍
- 完整实现 - 构建公司与产品时序图数据
- 查询案例-分析'消费品商贸'产业2020Q2季度总营收
- 其他资料
数据模型的设计
行业、产品、公司相关的产业链数据建模,包含产品层级图谱、行业分层图谱、产业链上下游图谱、公司与产品图谱等。如下主要是公司与产品营收的时序图数据建模实现方案。
函数与过程功能介绍
- HTTP请求
RETURN olab.http.post('api-address','input')- 重置MAP-移除传入的KEY
RETURN olab.reset.map({map},{keys}) AS value- 生成JSON-STRING
RETURN olab.convert.json({object})
完整实现 - 构建公司与产品时序图数据
- 在下面的实现中营收相关的时序数据使用JSON格式数据建模存储在关系的属性中
下述实现中集成了GraphQL-API、olab-apoc组件、访问数据库等操作,构建的图数据最终是将时序数据存储在了一个JSON数组中。
CALL apoc.periodic.iterate('CALL apoc.load.jdbc(\'jdbc:mysql://contentdb.crkldnwly6ki.rds.cn-north-1.amazonaws.com.cn:3306/database?user=datalab_dev&password=datalabgogo&useUnicode=true&characterEncoding=utf8&serverTimezone=UTC\',
\'SELECT calc.company_id AS fromCompanyId,pro.`name` AS `to`,CONVERT(DATE_FORMAT(calc.report_date,\\\'%Y%m%d%H%i%S\\\'),UNSIGNED INTEGER)
AS report_date,income,profit,product_income,product_income_ratio,product_profit,product_profit_ratio,\\\'id\\\' AS uniqueField,calc.id AS uniqueFieldID,\\\'chinascope_supply_chain.fin_secu_sam_product_calc\\\' AS jsDataApi FROM fin_secu_sam_product_calc calc RIGHT JOIN dict_product_rs pro ON calc.product_code=pro.`code` WHERE calc.update_time>=DATE_SUB(NOW(),INTERVAL 1 DAY)\')',
'WITH REPLACE(\'{"query": "{ horgByName(sourceCode: \\\\\\"company-id\\\\\\", sourceFlag: \\\\\\"chinascope\\\\\\") { name hcode }}","variables": null}\',\'company-id\',row.fromCompanyId) AS query,row WITH apoc.convert.fromJsonMap(olab.http.post(\'http://ip/ongdb/graphql\',query))
AS result,row WHERE result IS NOT NULL WITH result.data.horgByName[0].hcode AS fromHcode,result.data.horgByName[0].name AS fromName,row WHERE fromHcode IS NOT NULL WITH fromHcode,fromName,row.to AS toName,row
WITH fromHcode,fromName,\'HPRDCLS\'+apoc.util.md5([toName]) AS toHcode,row MERGE (from:HORGProductCalc {hcode:fromHcode}) SET from.name=fromName,from:HORG WITH from,toHcode,row MATCH (to:产业 {hcode:toHcode})
WITH from,to,row WHERE from<>to WITH from,to,olab.reset.map(row,[\'fromCompanyId\',\'to\']) AS row OPTIONAL MATCH (from)-[r]->(to) WITH from,to,row,apoc.coll.union(apoc.convert.fromJsonList(r.detail),[row]) AS detail
WITH from,to,row,olab.convert.json(detail) AS detail,SIZE(detail) AS detail_size MERGE (from)-[r:产品]->(to) SET r.detail=detail,r.detail_size=detail_size', {parallel:false,batchSize:100})
YIELD batches,total,timeTaken,committedOperations,failedOperations,failedBatches,retries,errorMessages,batch,operations RETURN batches,total,timeTaken,committedOperations,failedOperations,failedBatches,retries,errorMessages,batch,operations;
查询案例-分析’消费品商贸’产业2020Q2季度总营收
- 查询’消费品商贸’行业下级分类中所有相关产品
数据建模时产品与行业有关联关系,因此在这里使用时可以直接得到,关注的某行业下属子子孙孙行业的所有产品。
# 扩展PATH方式MATCH (indus:行业) WHERE indus.name='消费品商贸' WITH indusCALL apoc.path.expandConfig(indus,{maxLevel:3, relationshipFilter:'NEXT>|<BELONG_TO', labelFilter:'+产业|/产品', bfs:false, filterStartNode:true,uniqueness:'NODE_GOLBEL', limit:-1}) YIELD pathWITHpathRETURNpath
# 扩展NODE方式
MATCH (indus:行业) WHERE indus.name='消费品商贸' WITH indus
CALL apoc.path.subgraphNodes(indus,{maxLevel:3, relationshipFilter:'NEXT>|<BELONG_TO',
labelFilter:'+产业|/产品', bfs:false, filterStartNode:true,uniqueness:'NODE_GOLBEL', limit:-1})
YIELD node WITH node
RETURN node行业与产品关联结构示意图
- '消费品商贸’行业相关的产品【相关指从属关系的划分,这里拿出了下属三层以内的产业相关产品】2020Q2营收分析【案例实现营收加总】
MATCH (indus:行业) WHERE indus.name='消费品商贸' WITH indus
CALL apoc.path.subgraphNodes(indus,{maxLevel:3, relationshipFilter:'NEXT>|<BELONG_TO',
labelFilter:'+产业|/产品', bfs:false, filterStartNode:true,uniqueness:'NODE_GOLBEL', limit:-1}) YIELD node WITH node
MATCH p=(node)<-[r:产品]-(:HORGProductCalc) WITH apoc.convert.fromJsonList(r.detail) AS detail
UNWIND detail AS map
WITH map WHERE TOINTEGER(map.report_date)>=20200331000000 AND TOINTEGER(map.report_date)<=20200630000000
WITH TOINTEGER(map.income) AS income
RETURN SUM(income)
# 加总后的总营收两万亿
╒═════════════╕
│"SUM(income)"│
╞═════════════╡
│2215100453627│
└─────────────┘- 产品与公司的样例图结构。
其他资料
- olab-apoc组件
https://github.com/ongdb-contrib/ongdb-lab-apoc- apoc组件【Neo4j官方开源组件】
https://github.com/neo4j-contrib/neo4j-apoc-procedures边栏推荐
- [hcie TAC] question 5 - 1
- China's plastic processing machinery market trend report, technological innovation and market forecast
- error: ‘connect‘ was not declared in this scope connect(timer, SIGNAL(timeout()), this, SLOT(up
- Hair growth shampoo industry Research Report - market status analysis and development prospect forecast
- What encryption algorithm is used for the master password of odoo database?
- L1-072 scratch lottery
- Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
- Common knowledge of unity Editor Extension
- Selenium browser (2)
- CMPSC311 Linear Device
猜你喜欢

I let the database lock the table! Almost fired!

一图看懂ThreadLocal

Filtered off site request to

程序员怎么才能提高代码编写速度?
时钟轮在 RPC 中的应用

QT graphical view frame: element movement

TypeError: list indices must be integers or slices, not str

《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下

Cut! 39 year old Ali P9, saved 150million

Actual combat | use composite material 3 in application
随机推荐
Unity script API - time class
Will the memory of ParticleSystem be affected by maxparticles
What does IOT engineering learn and work for?
Daily notes~
Hair and fuzz interceptor Industry Research Report - market status analysis and development prospect forecast
Interface fonctionnelle, référence de méthode, Widget de tri de liste implémenté par lambda
TypeError: not enough arguments for format string
The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
DIY a low-cost multi-functional dot matrix clock!
Principle and general steps of SQL injection
[flask] ORM one to many relationship
[book club issue 13] coding format of video files
Can I "reverse" a Boolean value- Can I 'invert' a bool?
Feature extraction and detection 15-akaze local matching
Salient map drawing based on OpenCV
[native JS] optimized text rotation effect
Nine CIO trends and priorities in 2022
Application of clock wheel in RPC
[Chongqing Guangdong education] National Open University spring 2019 1248 public sector human resource management reference questions
Web components series - detailed slides