Skip to content

Commit

Permalink
feat: add CourseAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
RybakovaIE committed Feb 27, 2024
1 parent 4aeb365 commit a2f5ffa
Show file tree
Hide file tree
Showing 9 changed files with 1,522 additions and 2 deletions.
1,164 changes: 1,164 additions & 0 deletions kb/course_works/1217xx.scs

Large diffs are not rendered by default.

162 changes: 162 additions & 0 deletions kb/course_works/section_of_course_works.scs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
concept_course_work
<-sc_node_not_relation;
=> nrel_main_idtf:
[курсовая работа]
(*<-lang_ru;;*);
[course work]
(* <- lang_en;;*);
<- rrel_key_sc_element: ...
(*
<- sc_definition;;
=> nrel_main_idtf:
[Опр. (курсовая работа)] (* <- lang_ru;; *);;*);;

concept_student
<-sc_node_not_relation;
=> nrel_main_idtf:
[студент]
(*<-lang_ru;;*);
[student]
(* <- lang_en;;*);
<- rrel_key_sc_element: ...
(*
<- sc_definition;;
=> nrel_main_idtf:
[Опр. (студент)] (* <- lang_ru;; *);;*);;

concept_teacher
<-sc_node_not_relation;
=> nrel_main_idtf:
[преподаватель]
(*<-lang_ru;;*);
[teacher]
(* <- lang_en;;*);
<- rrel_key_sc_element: ...
(*
<- sc_definition;;
=> nrel_main_idtf:
[Опр. (преподаватель)] (* <- lang_ru;; *);;*);;

concept_project
<-sc_node_not_relation;
=> nrel_main_idtf:
[проект]
(*<-lang_ru;;*);
[project]
(* <- lang_en;;*);
<- rrel_key_sc_element: ...
(*
<- sc_definition;;
=> nrel_main_idtf:
[Опр. (проект)] (* <- lang_ru;; *);;*);;

nrel_project
<-sc_node_norole_relation;
<- binary_relation;
<- oriented_relation;
<- antireflexive_relation;
<- antisymmetric_relation;
<- antitransitive_relation;
=> nrel_main_idtf:
[проект*]
(*<-lang_ru;;*);
[project*]
(* <- lang_en;;*);
<- rrel_key_sc_element: ...
(*
<- sc_definition;;
=> nrel_main_idtf:
[Опр. (проект)] (* <- lang_ru;; *);;*);;

nrel_best_project
<-sc_node_norole_relation;
<- binary_relation;
<- oriented_relation;
<- antireflexive_relation;
<- antisymmetric_relation;
<- antitransitive_relation;
=> nrel_main_idtf:
[лучшие проект*]
(*<-lang_ru;;*);
[best project*]
(* <- lang_en;;*);
<- rrel_key_sc_element: ...
(*
<- sc_definition;;
=> nrel_main_idtf:
[Опр. (лучший проект)] (* <- lang_ru;; *);;*);;

nrel_curator
<-sc_node_norole_relation;
<- binary_relation;
<- oriented_relation;
<- antireflexive_relation;
<- antisymmetric_relation;
<- antitransitive_relation;
=> nrel_main_idtf:
[куратор*]
(*<-lang_ru;;*);
[curator*]
(* <- lang_en;;*);
<- rrel_key_sc_element: ...
(*
<- sc_definition;;
=> nrel_main_idtf:
[Опр. (куратор)] (* <- lang_ru;; *);;*);;

nrel_inspector
<-sc_node_norole_relation;
<- binary_relation;
<- oriented_relation;
<- antireflexive_relation;
<- antisymmetric_relation;
<- antitransitive_relation;
=> nrel_main_idtf:
[инспектор*]
(*<-lang_ru;;*);
[inspector*]
(* <- lang_en;;*);
<- rrel_key_sc_element: ...
(*
<- sc_definition;;
=> nrel_main_idtf:
[Опр. (инспектор)] (* <- lang_ru;; *);;*);;

nrel_final_grade
<-sc_node_norole_relation;
<- binary_relation;
<- oriented_relation;
<- antireflexive_relation;
<- antisymmetric_relation;
<- antitransitive_relation;
=> nrel_main_idtf:
[итоговая оценка*]
(*<-lang_ru;;*);
[final grade*]
(* <- lang_en;;*);
<- rrel_key_sc_element: ...
(*
<- sc_definition;;
=> nrel_main_idtf:
[Опр. (итоговая оценка)] (* <- lang_ru;; *);;*);;

nrel_assignment_sheet_due_date
<-sc_node_norole_relation;
<- binary_relation;
<- oriented_relation;
<- antireflexive_relation;
<- antisymmetric_relation;
<- antitransitive_relation;
=> nrel_main_idtf:
[дата сдачи листа задания*]
(*<-lang_ru;;*);
[assignment sheet due date*]
(* <- lang_en;;*);
<- rrel_key_sc_element: ...
(*
<- sc_definition;;
=> nrel_main_idtf:
[Опр. (дата сдачи листа задания)] (* <- lang_ru;; *);;*);;



21 changes: 21 additions & 0 deletions kb/course_works/section_subject_domain_of_course_works.scs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
section_of_course_works
=> nrel_main_idtf:
[Раздел. Предметная область курсовых работ]
(* <- lang_ru;; *);
[Section. Subject domain of course works] (* <- lang_en;; *);;
section_of_anatomy_of_course_works<=nrel_section_decomposition:{
subject_domain_of_course_works
};;
section_of_course_works->rrel_key_sc_element:
concept_student;
concept_project;
concept_teacher;
concept_course_work;;

section_of_course_works->rrel_explored_relation:
nrel_project;
nrel_best_project;
nrel_curator;
nrel_inspector;
nrel_final_grade;
nrel_assignment_sheet_due_date;;
9 changes: 9 additions & 0 deletions kb/course_works/subject_domain_of_course_works.scs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ubject_domain_of_course_works
=>nrel_main_idtf: [Предметная область курсовых работ] (* <- lang_ru;; *);
[subject domain of course works] (* <- lang_en;; *);
<- not_enough_formed_structure;;


subject_domain_of_course_works->rrel_maximum_studied_object_class:concept_course_work;;
subject_domain_of_course_works->rrel_not_maximum_studied_object_class:concept_project;;
subject_domain_of_course_works<-subject_domain;;
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,29 @@ action_show_weather
[Action. show weather is an action of receiving information about the weather at a specific location](* <- lang_en;; *);;
*);;
*);;

action_show_course
<- sc_node_class;
=> nrel_main_idtf:
[действие. узнать о курсе](* <- lang_ru;; *);
[action. show course](* <- lang_en;; *);
<- actions_class;
<- atomic_action_class;
<= nrel_inclusion: information_action;
<- rrel_key_sc_element:
...
(*
<- explanation;;
<= nrel_sc_text_translation:
...
(*
-> rrel_example:
[Действие. узнать узнать о курсе](* <- lang_ru;; *);;
*);
...
(*
-> rrel_example:
[Action. show course](* <- lang_en;; *);;
*);;
*);;

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ subject_domain_of_actions_and_tasks
action_reply_to_message;
action_find_word_in_set_by_first_letter;
action_show_weather;
action_show_course;
action_standard_message_reply;
-> rrel_explored_relation:
rrel_dynamic_argument;;
124 changes: 124 additions & 0 deletions problem-solver/py/modules/messageProcessingModule/CourseAgent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""
This code creates some test agent and registers until the user stops the process.
For this we wait for SIGINT.
"""
import gspread
import pandas as pd
import os
from google.oauth2 import service_account

import logging
from sc_client.models import ScAddr
from sc_client.constants import sc_types

from sc_client.client import template_search
from sc_client.models import ScAddr, ScLinkContentType, ScTemplate
from sc_kpm import ScAgentClassic, ScModule, ScResult, ScServer
from sc_kpm.utils import (
create_link,
get_link_content_data,
check_edge, create_edge,
)
from sc_kpm.utils.action_utils import (
finish_action_with_status,
get_action_arguments
)
from sc_kpm import ScKeynodes

logging.basicConfig(
level=logging.INFO, format="%(asctime)s | %(name)s | %(message)s", datefmt="[%d-%b-%y %H:%M:%S]"
)

class CourseAgent(ScAgentClassic):
def __init__(self):
super().__init__("action_show_course")

def on_event(self, event_element: ScAddr, event_edge: ScAddr, action_element: ScAddr) -> ScResult:
result = self.run(action_element)
is_successful = result == ScResult.OK
finish_action_with_status(action_element, is_successful)
self.logger.info("CourseAgent finished %s",
"successfully" if is_successful else "unsuccessfully")
return result

def get_groups_sheets(self, spreadsheet):
sheets = spreadsheet.worksheets()
i = 0
while i < len(sheets):
if sheets[i].title.isdigit(): i+=1
else: sheets.pop(i)
return sheets

def run(self, action_node: ScAddr) -> ScResult:
self.logger.info("CourseAgent started")

try:
message_addr = get_action_arguments(action_node, 1)[0]
message_type = ScKeynodes.resolve(
"concept_message_about_course", sc_types.NODE_CONST_CLASS)

if not check_edge(sc_types.EDGE_ACCESS_VAR_POS_PERM, message_type, message_addr):
self.logger.info(
f"CourseAgent: the message isn’t about course")
return ScResult.OK
except:
self.logger.info(f"CourseAgent: finished with an error")
return ScResult.ERROR

course_work = 'course_work_12170x'
projects = set()

path_to_directory = os.getcwd()

SERVICE_ACCOUNT_FILE = f'{path_to_directory}/modules/messageProcessingModule/keys.json'.replace('/scripts', '/problem-solver/py')
#SERVICE_ACCOUNT_FILE = '/home/anna/projects/forks/nika/problem-solver/py/modules/messageProcessingModule/keys.json'
SCOPES = ["https://www.googleapis.com/auth/spreadsheets.readonly"]

credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
client = gspread.authorize(credentials)

url = "https://docs.google.com/spreadsheets/d/1KrXHlI6p_qM77Ps0P8WgbP3Tusjru40g1yNFBv9EE08/edit#gid=0"
spreadsheet = client.open_by_url(url)
sheets = self.get_groups_sheets(spreadsheet)

groups_name = f'{sheets[0].title[:-2]}xx'
path_to_directory = path_to_directory.replace('scripts', 'kb/course_works')

file = open(f'{path_to_directory}/{groups_name}.scs', 'a+', encoding = 'utf-8')

file.write(f"{course_work}\n<-sc_node_not_relation;\n<-concept_course_work;;\n\n")

for sheet in sheets:
students = pd.DataFrame(data=sheet.get_values())
for i in range(len(students)):

fullname = students[1][i]
if fullname == 'ФИО' or fullname =='': continue
file.write(f"...\n<-sc_node_not_relation;\n<-concept_student;\n=>nrel__main_idtf:[{fullname}](*<-lang_ru;;*);\n")

grade = students[24][i]
if int(grade) > 0:
file.write(f"=>nrel_final_grade:{grade}(*\n\t<-sc_node_not_relation;;\n\t<-concept_number;;*);;\n")

current_project = students[2][i]
file.write(f"=>nrel_project:...(*\n\t<-sc_node_not_relation;;\n\t<-concept_project;;\n\t=>nrel__main_idtf:[{current_project}](*<-lang_ru;;*);;\n")

if not(current_project in projects):
curator = students[4][i]
inspector = students[5][i]
file.write(f"\t=>nrel_curator:...(*\n\t\t<-sc_node_not_relation;;\n\t\t<-concept_teacher;;\n\t\t=>nrel__main_idtf:[{curator}](*<-lang_ru;;*);;*);;\n")
file.write(f"\t=>nrel_inspector:...(*\n\t\t<-sc_node_not_relation;;\n\t\t<-concept_teacher;;\n\t\t=>nrel__main_idtf:[{inspector}](*<-lang_ru;;*);;*);;\n")
file.write(f"\t<=nrel_project:{course_work};;")
best_project = students[21][i]
if best_project != 'FALSE':
file.write(f"\t<=nrel_best_project:{course_work};;")
projects.add(current_project)

file.write("*);;\n\n")
due_date = students[6][i]

file.write(f"{course_work}\n=>nrel_assignment_sheet_due_date:{due_date}(*\n\t<-sc_node_not_relation;;\n\t<-concept_date;;*);;")
file.close()

return ScResult.OK
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sc_kpm import ScModule
from .WeatherAgent import WeatherAgent

from .CourseAgent import CourseAgent

class MessageProcessingModule(ScModule):
def __init__(self):
super().__init__(WeatherAgent())
super().__init__(WeatherAgent(), CourseAgent())
13 changes: 13 additions & 0 deletions problem-solver/py/modules/messageProcessingModule/keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "service_account",
"project_id": "courseworks-415411",
"private_key_id": "8565bfba25d8c8db230e741984bc5223c52aeb03",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHaHcyOExeEutw\niR4siC9XCcNfP9Cat5I42CBqB46FZraXXZg8t9nolWOCBb6hCRel67MP1E3DTxjK\nMkBuGUo1uxTP/4o2xHMVLAtpW8SXHY6s/KkrJ7SEF0hDPWSiZxmjB2oj7P1mJB2B\nMx7j4k1f0yYaKRoUI4zKM1srH5a3rQCfkiPUeVZpRqdtF+dy5KgM+095hNNoaby3\nzaOt5dMi0w/tGVIM4f4J7JEON+IV5KJplIbPzJL6khmpyJV03YlIzKldVwJKBEfy\nJNrUWZ3+Fo9EAbmJJjexPkTkeLhh1w0W59Cxc6gqQ1pr3gms/a3JaYxxfCsxUfZd\noCng01HLAgMBAAECggEABoZoFBgcg52J37pU5u8j4Wy73GOJr25fVgXYda++naXh\nRq203BPGCSLOSURn2vwhrne6ecOgMcpmTMN9MT0ZnQ18nlvFyYn/HAu/adirY6h/\ncTCpVnSrpwDeB/k70EagY6HL+tX36r42yvIBykIu9vpBTmzW4h7RrhIlIxGbDHKJ\naBfyJ9Yuf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END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "102999943030206345502",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/reader%40courseworks-415411.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}

0 comments on commit a2f5ffa

Please sign in to comment.