462 lines
15 KiB
Python
462 lines
15 KiB
Python
from elasticsearch import Elasticsearch
|
|
from datetime import datetime
|
|
|
|
# uni-server
|
|
es = Elasticsearch({'host':'inse.nes.uni-due.de', 'port': 443, 'path_prefix':'elastic', 'scheme':'https'}, basic_auth=('elastic', 'RLldUaJgbGeoqd3KCX3p'), request_timeout=60, max_retries=5, retry_on_timeout=True)
|
|
|
|
stat_dict = {}
|
|
index_name = "inse_stats"
|
|
|
|
def get_max_count():
|
|
print("Max_Count")
|
|
max_dict = {}
|
|
|
|
max_dict["count_projects_bmbf"] = int(es.count(index='projects_bmbf').get('count'))
|
|
max_dict["count_projects_eu"] = int(es.count(index='projects_eu').get('count'))
|
|
max_dict["count_projects_dfg"] = int(es.count(index='projects_dfg').get('count'))
|
|
max_dict["count_projects_all"] = max_dict["count_projects_bmbf"] + max_dict["count_projects_dfg"] + max_dict["count_projects_eu"]
|
|
|
|
max_dict["count_wos"] = int(es.count(index='wos_index_1.0').get('count'))
|
|
max_dict["count_startups"] = int(es.count(index='startups').get('count'))
|
|
max_dict["count_akutell"] = int(es.count(index='aktuell').get('count'))
|
|
max_dict["count_epo"] = int(es.count(index='epo_index_1.0').get('count'))
|
|
|
|
max_dict["count_ude_persons"] = int(es.count(index='ude_persons_1.0').get('count'))
|
|
max_dict["count_ude_publications"] = int(es.count(index='due_index_1.0').get('count'))
|
|
|
|
stat_dict["max_count"] = max_dict
|
|
|
|
def get_stat_persons():
|
|
print("Persons")
|
|
|
|
# get all persons
|
|
aggs = {
|
|
"lsf_id": {
|
|
"terms": {
|
|
"size": 100000,
|
|
"field": "lsf_id.keyword"
|
|
}
|
|
}
|
|
}
|
|
|
|
docs_aggs = es.search(index="ude_persons_1.0", aggs=aggs, size=0)
|
|
ids = docs_aggs.get("aggregations").get("lsf_id").get("buckets")
|
|
|
|
current_year = int(datetime.now().year)
|
|
|
|
all_names = []
|
|
|
|
for id in ids:
|
|
current_person = {}
|
|
lsf_id = id.get("key")
|
|
print(" - " + lsf_id)
|
|
query = {
|
|
"match": {
|
|
"lsf_id": lsf_id
|
|
}
|
|
}
|
|
hit = es.search(index="ude_persons_1.0", query=query, size=1).get("hits").get("hits")[0].get("_source")
|
|
surname = hit.get("surname")
|
|
firstname = hit.get("firstname")
|
|
name = hit.get("name")
|
|
|
|
# filter out names with unallowed chars like "/" or "+"
|
|
#if any(c not in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234 -öäüÖÜÄÁáĆćÉéÍíĹĺŃńÓóŐőŔশÚúŰűÝýŹź' for c in firstname):
|
|
# continue
|
|
#if any(c not in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234 -öäüÖÜÄÁáĆćÉéÍíĹĺŃńÓóŐőŔশÚúŰűÝýŹź' for c in surname):
|
|
# continue
|
|
if any(c in '()!%&/+/,;.' for c in firstname):
|
|
continue
|
|
if any(c in '()!%&/+/,;.' for c in surname):
|
|
continue
|
|
|
|
if name in all_names:
|
|
continue
|
|
else:
|
|
all_names.append(name)
|
|
|
|
current_person["name"] = name
|
|
current_person["surname"] = surname
|
|
current_person["firstname"] = firstname
|
|
current_person["lsf_id"] = lsf_id
|
|
|
|
# ude_publications
|
|
query = {
|
|
"nested": {
|
|
"path": "authors",
|
|
"query": {
|
|
"match": {
|
|
"authors.lsf_id": lsf_id
|
|
}
|
|
}
|
|
}
|
|
}
|
|
current_person["ude_publication_hits"] = es.search(index="due_index_1.0", query=query, size=0).get("hits").get("total").get("value")
|
|
|
|
# ude_publications_last_year
|
|
query = {
|
|
"bool": {
|
|
"must": [
|
|
{
|
|
"nested": {
|
|
"path": "authors",
|
|
"query": {
|
|
"match": {
|
|
"authors.lsf_id": lsf_id
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"range": {
|
|
"year.keyword": {
|
|
"gte": current_year - 1
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
current_person["ude_publication_hits_last_year"] = es.search(index="due_index_1.0", query=query, size=0).get("hits").get("total").get("value")
|
|
|
|
# check requirements for following analysis
|
|
if firstname == "" or surname == "":
|
|
es.index(index=index_name, id=lsf_id, document=current_person)
|
|
continue
|
|
|
|
# akutell
|
|
query = {
|
|
"multi_match": {
|
|
"query": firstname + " " + surname,
|
|
"fields": ["*"],
|
|
"type" : "phrase"
|
|
}
|
|
}
|
|
current_person["akutell_hits"] = es.search(index="aktuell", query=query, size=0).get("hits").get("total").get("value")
|
|
|
|
# akutell_last_year
|
|
query = {
|
|
"bool": {
|
|
"must": [
|
|
{
|
|
"multi_match": {
|
|
"query": firstname + " " + surname,
|
|
"fields": ["*"],
|
|
"type" : "phrase"
|
|
}
|
|
},
|
|
{
|
|
"range": {
|
|
"date_year.keyword": {
|
|
"gte": current_year - 1
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
current_person["akutell_hits_last_year"] = es.search(index="aktuell", query=query, size=0).get("hits").get("total").get("value")
|
|
|
|
# wos_publications
|
|
"""
|
|
query = {
|
|
"match_phrase": {
|
|
"Author Full Name": surname + ", " + firstname[0]
|
|
}
|
|
}
|
|
"""
|
|
query = {
|
|
"bool": {
|
|
"must": [
|
|
{
|
|
"query_string": {
|
|
"default_field": "Author Full Name",
|
|
"query": firstname + " AND " + surname
|
|
}
|
|
}
|
|
],
|
|
"should": [
|
|
{
|
|
"query_string": {
|
|
"default_field": "Email Addresses",
|
|
"query": "@uni-due.de"
|
|
}
|
|
},
|
|
{
|
|
"match_phrase": {
|
|
"Affiliation": "University of Duisburg Essen"
|
|
}
|
|
}
|
|
],
|
|
"minimum_should_match": 1
|
|
}
|
|
}
|
|
current_person["wos_publication_hits"] = es.search(index="wos_index_1.0", query=query, size=0).get("hits").get("total").get("value")
|
|
|
|
# wos_publications_last_year
|
|
"""
|
|
query = {
|
|
"bool": {
|
|
"must": [
|
|
{
|
|
"match_phrase": {
|
|
"Author Full Name": surname + ", " + firstname[0]
|
|
}
|
|
},
|
|
{
|
|
"range": {
|
|
"Publication Year.keyword": {
|
|
"gte": current_year - 1
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
"""
|
|
query = {
|
|
"bool": {
|
|
"must": [
|
|
{
|
|
"query_string": {
|
|
"default_field": "Author Full Name",
|
|
"query": firstname + " AND " + surname
|
|
}
|
|
},
|
|
{
|
|
"range": {
|
|
"Publication Year.keyword": {
|
|
"gte": current_year - 1
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"should": [
|
|
{
|
|
"query_string": {
|
|
"default_field": "Email Addresses",
|
|
"query": "@uni-due.de"
|
|
}
|
|
},
|
|
{
|
|
"query_string": {
|
|
"default_field": "Affiliation",
|
|
"query": "University of Duisburg Essen"
|
|
}
|
|
}
|
|
],
|
|
"minimum_should_match": 1
|
|
}
|
|
}
|
|
current_person["wos_publication_hits_last_year"] = es.search(index="wos_index_1.0", query=query, size=0).get("hits").get("total").get("value")
|
|
|
|
# patents
|
|
query = {
|
|
"bool": {
|
|
"must": [
|
|
{
|
|
"match_phrase": {
|
|
"inventors_name_text": surname + ", " + firstname
|
|
}
|
|
},
|
|
{
|
|
"match_phrase": {
|
|
"applicants_name_text": "Universität Duisburg-Essen"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
current_person["patent_hits"] = es.search(index="epo_index_1.0", query=query, size=0).get("hits").get("total").get("value")
|
|
|
|
# patents_last_year
|
|
query = {
|
|
"bool": {
|
|
"must": [
|
|
{
|
|
"match_phrase": {
|
|
"inventors_name_text": surname + ", " + firstname
|
|
}
|
|
},
|
|
{
|
|
"match_phrase": {
|
|
"applicants_name_text": "Universität Duisburg-Essen"
|
|
}
|
|
},
|
|
{
|
|
"range": {
|
|
"date_publication_year": {
|
|
"gte": current_year - 1
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
current_person["patent_hits_last_year"] = es.search(index="epo_index_1.0", query=query, size=0).get("hits").get("total").get("value")
|
|
|
|
es.index(index=index_name, id=lsf_id, document=current_person)
|
|
|
|
|
|
def upload():
|
|
print("Uploading")
|
|
es.index(index=index_name, id="stats", document=stat_dict)
|
|
|
|
def check_elastic():
|
|
index_name = "inse_stats"
|
|
if not es.indices.exists(index=index_name):
|
|
settings = {
|
|
"analysis": {
|
|
"analyzer": {
|
|
"searchabilityAnalyzer": {
|
|
"type": "custom",
|
|
"tokenizer": "standard",
|
|
"filter": [
|
|
"lowercase",
|
|
"asciifolding"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
es.indices.create(index=index_name, settings=settings)
|
|
|
|
def get_best_10():
|
|
print("Best_10")
|
|
best_10 = {}
|
|
query = {
|
|
"match_all" : {}
|
|
}
|
|
|
|
### best_10_ever
|
|
# ude_publication_hits
|
|
sort = {
|
|
"ude_publication_hits": {
|
|
"order": "desc"
|
|
}
|
|
}
|
|
hits = es.search(index="inse_stats", query=query, sort=sort, size=10).get("hits").get("hits")
|
|
best_10_ude_publication_hits = {}
|
|
counter = 1
|
|
for hit in hits:
|
|
best_10_ude_publication_hits[str(counter)] = {"name": hit.get("_source").get("name"), "number": hit.get("sort")[0]}
|
|
counter += 1
|
|
best_10["best_10_ude_publication_hits"] = best_10_ude_publication_hits
|
|
|
|
# akutell_hits
|
|
sort = {
|
|
"akutell_hits": {
|
|
"order": "desc"
|
|
}
|
|
}
|
|
hits = es.search(index="inse_stats", query=query, sort=sort, size=10).get("hits").get("hits")
|
|
best_10_akutell_hits = {}
|
|
counter = 1
|
|
for hit in hits:
|
|
best_10_akutell_hits[str(counter)] = {"name": hit.get("_source").get("name"), "number": hit.get("sort")[0]}
|
|
counter += 1
|
|
best_10["best_10_akutell_hits"] = best_10_akutell_hits
|
|
|
|
# wos_publication_hits
|
|
sort = {
|
|
"wos_publication_hits": {
|
|
"order": "desc"
|
|
}
|
|
}
|
|
hits = es.search(index="inse_stats", query=query, sort=sort, size=10).get("hits").get("hits")
|
|
best_10_wos_publication_hits = {}
|
|
counter = 1
|
|
for hit in hits:
|
|
best_10_wos_publication_hits[str(counter)] = {"name": hit.get("_source").get("name"), "number": hit.get("sort")[0]}
|
|
counter += 1
|
|
best_10["best_10_wos_publication_hits"] = best_10_wos_publication_hits
|
|
|
|
# patent_hits
|
|
sort = {
|
|
"patent_hits": {
|
|
"order": "desc"
|
|
}
|
|
}
|
|
hits = es.search(index="inse_stats", query=query, sort=sort, size=10).get("hits").get("hits")
|
|
best_10_patent_hits = {}
|
|
counter = 1
|
|
for hit in hits:
|
|
best_10_patent_hits[str(counter)] = {"name": hit.get("_source").get("name"), "number": hit.get("sort")[0]}
|
|
counter += 1
|
|
best_10["best_10_patent_hits"] = best_10_patent_hits
|
|
|
|
### best_10_last year
|
|
# ude_publication_hits_last_year
|
|
sort = {
|
|
"ude_publication_hits_last_year": {
|
|
"order": "desc"
|
|
}
|
|
}
|
|
hits = es.search(index="inse_stats", query=query, sort=sort, size=10).get("hits").get("hits")
|
|
best_10_ude_publication_hits_last_year = {}
|
|
counter = 1
|
|
for hit in hits:
|
|
best_10_ude_publication_hits_last_year[str(counter)] = {"name": hit.get("_source").get("name"), "number": hit.get("sort")[0]}
|
|
counter += 1
|
|
best_10["best_10_ude_publication_hits_last_year"] = best_10_ude_publication_hits_last_year
|
|
|
|
# akutell_hits_last_year
|
|
sort = {
|
|
"akutell_hits_last_year": {
|
|
"order": "desc"
|
|
}
|
|
}
|
|
hits = es.search(index="inse_stats", query=query, sort=sort, size=10).get("hits").get("hits")
|
|
best_10_akutell_hits_last_year = {}
|
|
counter = 1
|
|
for hit in hits:
|
|
best_10_akutell_hits_last_year[str(counter)] = {"name": hit.get("_source").get("name"), "number": hit.get("sort")[0]}
|
|
counter += 1
|
|
best_10["best_10_akutell_hits_last_year"] = best_10_akutell_hits_last_year
|
|
|
|
# wos_publication_hits_last_year
|
|
sort = {
|
|
"wos_publication_hits_last_year": {
|
|
"order": "desc"
|
|
}
|
|
}
|
|
hits = es.search(index="inse_stats", query=query, sort=sort, size=10).get("hits").get("hits")
|
|
best_10_wos_publication_hits_last_year = {}
|
|
counter = 1
|
|
for hit in hits:
|
|
best_10_wos_publication_hits_last_year[str(counter)] = {"name": hit.get("_source").get("name"), "number": hit.get("sort")[0]}
|
|
counter += 1
|
|
best_10["best_10_wos_publication_hits_last_year"] = best_10_wos_publication_hits_last_year
|
|
|
|
# patent_hits_last_year
|
|
sort = {
|
|
"patent_hits_last_year": {
|
|
"order": "desc"
|
|
}
|
|
}
|
|
hits = es.search(index="inse_stats", query=query, sort=sort, size=10).get("hits").get("hits")
|
|
best_10_patent_hits_last_year = {}
|
|
counter = 1
|
|
for hit in hits:
|
|
best_10_patent_hits_last_year[str(counter)] = {"name": hit.get("_source").get("name"), "number": hit.get("sort")[0]}
|
|
counter += 1
|
|
best_10["best_10_patent_hits_last_year"] = best_10_patent_hits_last_year
|
|
|
|
stat_dict["best_10"] = best_10
|
|
|
|
if __name__ == '__main__':
|
|
print("Starting")
|
|
check_elastic()
|
|
|
|
get_max_count()
|
|
|
|
get_stat_persons()
|
|
|
|
get_best_10()
|
|
|
|
upload()
|
|
|
|
print("Done")
|
|
|
|
|