Skip to content
Snippets Groups Projects
Commit ac217572 authored by Anton Bagliy's avatar Anton Bagliy
Browse files

ADD: sending grades into grade api #61

parent df50d7da
Branches
No related merge requests found
......@@ -10,18 +10,18 @@ install:
script:
- msbuild /p:TargetFrameworkVersion="v4.0"
- nunit-console -labels TestSimpleLexer/bin/Debug/TestSimpleLexer.dll
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR}
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR} ${TRAVIS_REPO_SLUG}
- nunit-console -labels TestLexer/bin/Debug/TestLexer.dll
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR}
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR} ${TRAVIS_REPO_SLUG}
- nunit-console -labels TestGeneratedLexer/bin/Debug/TestGeneratedLexer.dll
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR}
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR} ${TRAVIS_REPO_SLUG}
- nunit-console -labels TestDescentParser/bin/Debug/TestDescentParser.dll
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR}
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR} ${TRAVIS_REPO_SLUG}
- nunit-console -labels TestGeneratedParser/bin/Debug/TestGeneratedParser.dll
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR}
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR} ${TRAVIS_REPO_SLUG}
- nunit-console -labels TestASTParser/bin/Debug/TestASTParser.dll
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR}
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR} ${TRAVIS_REPO_SLUG}
- nunit-console -labels TestVisitors/bin/Debug/TestVisitors.dll
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR}
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR} ${TRAVIS_REPO_SLUG}
- nunit-console -labels TestCodeGenerator/bin/Debug/TestCodeGenerator.dll
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR}
- mono NunitReportParser/bin/Debug/NunitReportParser.exe ${TRAVIS_BUILD_DIR} ${TRAVIS_REPO_SLUG}
......@@ -5,6 +5,10 @@ using System.Runtime.CompilerServices;
using System.Xml;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
using System.IO;
using System.Net.Mime;
using System.Runtime.InteropServices;
namespace NunitReport
{
......@@ -32,7 +36,44 @@ namespace NunitReport
}
}
static void CountGrades()
static void SendGrades(JObject settings, int recordBookID, int submoduleID, int disciplineID, double value)
{
//System.Console.Out.WriteLine("{0}-{1}-{2}-{3}", RecordBookID, SubmoduleID, DisciplineID, value);
string gradeToken = (string) settings["GradeService"]["token"];
string gradeUrl = (string) settings["GradeService"]["url"];
string url = gradeUrl + "api/v0/sendGrades?token=" + gradeToken;
System.Console.Out.WriteLine(url);
WebRequest request;
request = WebRequest.Create(url);
request.Method = "PUT";
request.ContentType = "application/json charset=utf-8";
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
string json = "{\"discipline\":"+ disciplineID.ToString() +"," +
"\"recordbook\":"+ recordBookID.ToString() +"," +
"\"submodules\": [" +
"{" +
"\"id\":" + submoduleID.ToString() + "," +
"\"value\":" + value.ToString(System.Globalization.CultureInfo.InvariantCulture) +
"}" +
"]" +
"}";
System.Console.WriteLine(json);
streamWriter.Write(json);
}
Stream objStream;
var httpResponse = (HttpWebResponse) request.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
System.Console.Out.WriteLine(result);
}
}
static void CountGrades(string userName)
{
string configPath = @"../../../grades/Grades.json";
if (basePath != "")
......@@ -80,29 +121,54 @@ namespace NunitReport
//System.Console.Out.WriteLine(countedGrades[caseClass]);
}
int discipline = (int) grades["Discipline"]["ID"];
foreach (KeyValuePair<string, double> g in countedGrades)
{
if (g.Value > 0)
{
double grade = g.Value;
grade *= 0.6;
System.Console.Out.WriteLine(g.Key + " = " + grade.ToString());
int recordBook = (int) grades["RecordBooks"][userName];
JArray allTasks = (JArray) grades["Tasks"];
foreach (JObject task in allTasks)
{
if ((string) task["name"] == g.Key)
{
JArray modules = (JArray) task["modules"];
foreach (JObject module in modules)
{
int moduleid = (int) module["id"];
double w = (double) module["weight"];
double v = w * grade;
SendGrades(grades, recordBook, moduleid, discipline, v);
}
}
}
}
}
}
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
string filePath;
string userName;
if (args.Length > 0)
{
basePath = args[0];
filePath = basePath + @"/TestResult.xml";
userName = args[1].Split('/')[0];
}
else
{
userName = "czen";
filePath = @"./TestResult.xml";
}
doc.Load(filePath);
......@@ -127,7 +193,7 @@ namespace NunitReport
}
}
CountGrades();
CountGrades(userName);
System.Console.WriteLine("number of running tests: " + cases.Count);
}
......
{
"RecordBooks": {
"czen": 148
},
"GradeService": {
"url": "http://grade/~dev_rating/",
"token": "39se9832fh3e78fl23ois33mhfdff34gbuj34896"
},
"Discipline": {
"ID": 3726
},
"Tasks": [
{ "name": "TestSimpleLexer",
"modules": [
{
"id": 35712,
"weight": 0.5
},
{
"id": 35713,
"weight": 0.5
},
],
"grades": {
"TestId": 0,
......@@ -24,6 +44,16 @@
}
},
{ "name": "TestLexer",
"modules": [
{
"id": 35710,
"weight": 0.5
},
{
"id": 35711,
"weight": 0.5
},
],
"grades": {
"TestIntParse": 0.2,
"TestIntFailDot": 0.2,
......@@ -69,6 +99,16 @@
}
},
{ "name": "TestGeneratedLexer",
"modules": [
{
"id": 35714,
"weight": 0.5
},
{
"id": 35715,
"weight": 0.5
},
],
"grades": {
"TestIdCount": 1.5,
"TestIdInfo": 2,
......@@ -83,6 +123,16 @@
}
},
{ "name": "TestGeneratedParser",
"modules": [
{
"id": 35721,
"weight": 0.5
},
{
"id": 35722,
"weight": 0.5
},
],
"grades": {
"TestWhile": 2,
"TestRepeat": 2,
......@@ -94,6 +144,16 @@
}
},
{ "name": "TestDescentParser",
"modules": [
{
"id": 35719,
"weight": 0.5
},
{
"id": 35720,
"weight": 0.5
},
],
"grades": {
"TestWhile": 3,
"TestFor": 4,
......@@ -102,6 +162,16 @@
}
},
{ "name": "TestASTParser",
"modules": [
{
"id": 35723,
"weight": 0.5
},
{
"id": 35724,
"weight": 0.5
},
],
"grades": {
"TestWhile": 2,
"TestRepeat": 2,
......@@ -113,6 +183,16 @@
}
},
{ "name": "TestCodeGenerator",
"modules": [
{
"id": 35726,
"weight": 0.4444
},
{
"id": 35727,
"weight": 0.5555
},
],
"grades": {
"SmokeTest": 0,
"TestOutput": 0,
......@@ -123,6 +203,12 @@
}
},
{ "name": "TestVisitors",
"modules": [
{
"id": 35725,
"weight": 0.5
}
],
"grades": {
"NoLoopTest": 0.5,
"ThreeLoopsTest": 0.5,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment