d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Can Someone Write A Program For Me? > 500 Fg
123Next
Add Reply New Topic New Poll
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Feb 18 2016 10:07am
Exam Corrector Program:

Input Data:

Student Answers: AABCDBCBDBBC DDDD AA
Correct Answers: AABCDBCBAAAA EEEE AB

Output:
Section 1:
Score: 9/13
Percentage: 69.2%
Answer Analysis:
#10: You marked: D. Correct Answer: A
#11: You marked: B. Correct Answer: A
#12: You marked: B. Correct Answer: A
#13: You marked: C. Correct Answer: A

Section 2:
Score: 0/4
Percentage: 0%
Answer Analysis:
#1: You marked: D. Correct Answer: E
#2: You marked: D. Correct Answer: E
#3: You marked: D. Correct Answer: E
#4: You marked: D. Correct Answer: E

Section 3:
Score: 1/2
Percentage: 50%
Answer Analysis:
#2: You marked: A. Correct Answer: B

Overall:
Number of Sections: 3
Total Score: 10/19
Standardized Score: [Insert SAT Conversion Formula]

==================================================================
Also: Instead of input data for student answer being entered as: Student Answers: AABCDBCBDBBC DDDD AA:

I would like for it to also be entered as:

1. A
2. A
3. B
4. C
5. D
6. B
7. C
8. D
9. B
10. D
11. B
12. B
13. C

1. D
2. D
3. D
4. D

1. A
2. A

==================================================================

I would also like the ability to enter in multiple strings of Data. For example, above, it only showed one student's answer data. I would like the ability to run many students at the same time.

Example:

Input Data:

Bob Answers: AABCDBCBDBBC DDDD AA
Joe Answers: AABCDBCBDBBC EEEE FF
Sam Answers: AABCDBCBDBBC CCCC BB
Correct Answers: AABCDBCBAAAA EEEE AB

==================================================================

Regarding the language: I use a chromebook so I can not download any programs. I don't care what language it is, as long as I can access it from online. Python has an online compiler, but I"m not sure if you can input data into it.
Member
Posts: 20,928
Joined: Mar 18 2009
Gold: 435,910.13
Feb 18 2016 11:51pm
ill do this for 1k
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 19 2016 04:21am
You said language didn't matter, and you wanted it available online. So I whipped up a WCF web service. The service returns all the data you need. I haven't wired up a front end for it to display the data in the format you want. But the service does indeed do what you want it to.

CONTRACT TYPES
Code

using System.Runtime.Serialization;
namespace Correctamundo.Wcf.ContractTypes
{
[DataContract]
public class Question
{
[DataMember]
public bool IsCorrect { get; set; }

[DataMember]
public string Answer { get; set; }
}
}

using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Correctamundo.Wcf.ContractTypes
{
[DataContract]
public class Section
{
[DataMember]
public IEnumerable<Question> Questions { get; set; }
}
}

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Correctamundo.Wcf.ContractTypes
{
[DataContract]
public class Test
{
[DataMember]
public Guid Id { get; set; }

[DataMember]
public IEnumerable<Section> Sections { get; set; }
}
}


OPERATION TYPES
Code

using System.Runtime.Serialization;
namespace Correctamundo.Wcf.OperationTypes
{
[DataContract]
public class TestCorrectorRequest
{
}
}

using System.Runtime.Serialization;
namespace Correctamundo.Wcf.OperationTypes
{
[DataContract]
public class TestCorrectorResponse
{
[DataMember]
bool Success { get; set; }

[DataMember]
string Response { get; set; }
}
}

using Correctamundo.Wcf.ContractTypes;
using Correctamundo.Wcf.OperationTypes;
namespace Correctamundo.Wcf.OperationTypes
{
public class CorrectAnswersRequest : TestCorrectorRequest
{
public Test Test { get; set; }
}

}

using Correctamundo.Wcf.ContractTypes;
using Correctamundo.Wcf.OperationTypes;
namespace Correctamundo.Wcf.OperationTypes
{
public class CorrectAnswersResponse : TestCorrectorResponse
{
public Test Test { get; set; }

public bool Success { get; set; }

public string Response { get; set; }
}
}


FACTORIES
Code

using Correctamundo.Wcf.ContractTypes;
using Correctamundo.Wcf.OperationTypes;
namespace Correctamundo.Wcf.Factories.Interfaces
{
public interface IResponseFactory
{
CorrectAnswersResponse CreateCorrectAnswersResponse(bool success, string response, Test test = null);
}
}

using Correctamundo.Wcf.ContractTypes;
using Correctamundo.Wcf.Factories.Interfaces;
using Correctamundo.Wcf.OperationTypes;
namespace Correctamundo.Wcf.Factories.Implementations
{
public class ResponseFactory : IResponseFactory
{
public CorrectAnswersResponse CreateCorrectAnswersResponse(bool success, string response, Test test = null)
{
return new CorrectAnswersResponse
{
Success = success,
Response = response,
Test = test
};
}
}
}


TYPEMAPPERS
Code

namespace Correctamundo.Wcf.TypeMappers.Interfaces
{
public interface ITestMapper
{
Domain.Entities.Test Map(ContractTypes.Test test);
ContractTypes.Test Map(Domain.Entities.Test test);
}
}

namespace Correctamundo.Wcf.TypeMappers.Interfaces
{
public interface ISectionMapper
{
Domain.Entities.Section Map(ContractTypes.Section test);
ContractTypes.Section Map(Domain.Entities.Section test);
}
}

namespace Correctamundo.Wcf.TypeMappers.Interfaces
{
public interface IQuestionMapper
{
Domain.Entities.Question Map(ContractTypes.Question test);
ContractTypes.Question Map(Domain.Entities.Question test);
}
}

namespace Correctamundo.Wcf.TypeMappers.Implementations
{
public class TestMapper : ITestMapper
{
private readonly ISectionMapper _mapper;

public TestMapper(ISectionMapper mapper)
{
if (mapper == null)
throw new ArgumentNullException("mapper");

_mapper = mapper;
}

public Domain.Entities.Test Map(ContractTypes.Test test)
{
IEnumerable<Domain.Entities.Section> sections = MapFrom(test.Sections);
return new Domain.Entities.Test(sections);
}

private IEnumerable<Domain.Entities.Section> MapFrom(IEnumerable<ContractTypes.Section> sections)
{
foreach (ContractTypes.Section q in sections)
{
yield return _mapper.Map(q);
}
}

public ContractTypes.Test Map(Domain.Entities.Test test)
{
IEnumerable<ContractTypes.Section> sections = MapFrom(test.Sections);
return new ContractTypes.Test
{
Sections = sections
};
}

private IEnumerable<ContractTypes.Section> MapFrom(IEnumerable<Domain.Entities.Section> sections)
{
foreach (Domain.Entities.Section q in sections)
{
yield return _mapper.Map(q);
}
}
}
}

namespace Correctamundo.Wcf.TypeMappers.Implementations
{
public class SectionMapper : ISectionMapper
{
private readonly IQuestionMapper _mapper;

public SectionMapper(IQuestionMapper mapper)
{
if (mapper == null)
throw new ArgumentNullException("mapper");

_mapper = mapper;
}

public Domain.Entities.Section Map(ContractTypes.Section test)
{
IEnumerable<Domain.Entities.Question> questions = MapFrom(test.Questions);
return new Domain.Entities.Section(questions);
}

private IEnumerable<Domain.Entities.Question> MapFrom(IEnumerable<ContractTypes.Question> questions)
{
foreach(ContractTypes.Question q in questions)
{
yield return _mapper.Map(q);
}
}

public ContractTypes.Section Map(Domain.Entities.Section test)
{
IEnumerable<ContractTypes.Question> questions = MapFrom(test.Questions);
return new ContractTypes.Section
{
Questions = questions
};
}

private IEnumerable<ContractTypes.Question> MapFrom(IEnumerable<Domain.Entities.Question> questions)
{
foreach (Domain.Entities.Question q in questions)
{
yield return _mapper.Map(q);
}
}
}
}

namespace Correctamundo.Wcf.TypeMappers.Implementations
{
public class QuestionMapper : IQuestionMapper
{
public Domain.Entities.Question Map(ContractTypes.Question test)
{
return new Domain.Entities.Question(test.Answer, test.IsCorrect);
}

public ContractTypes.Question Map(Domain.Entities.Question test)
{
return new ContractTypes.Question
{
Answer = test.Answer,
IsCorrect = test.IsCorrect
};
}
}
}



WCF SERVICES
Code

namespace Correctamundo.Wcf.Services.Interfaces
{
[ServiceContract]
public interface ITestCorrectorService
{
[OperationContract]
CorrectAnswersResponse AddCorrectAnswers(CorrectAnswersRequest request);

[OperationContract]
CorrectAnswersResponse GetCorrectAnswers(CorrectAnswersRequest request);

}

}

namespace Correctamundo.Wcf.Services.Implementations
{
public class TestCorrectorService : ITestCorrectorService
{
private readonly ITestCorrector _testCorrector;
private readonly IResponseFactory _responseFactory;
private readonly ITestMapper _mapper;

public TestCorrectorService(ITestCorrector testCorrector, IResponseFactory responseFactory, ITestMapper mapper)
{
if (testCorrector == null)
throw new ArgumentNullException("testCorrector");
if (responseFactory == null)
throw new ArgumentNullException("responseFactory");
if (mapper == null)
throw new ArgumentNullException("mapper");


_testCorrector = testCorrector;
_responseFactory = responseFactory;
_mapper = mapper;
}

public CorrectAnswersResponse AddCorrectAnswers(CorrectAnswersRequest request)
{
CorrectAnswersResponse response;

try
{
Domain.Entities.Test test = _mapper.Map(request.Test);


Guid id = _testCorrector.AddTestKey(test);

request.Test.Id = id;

response = _responseFactory.CreateCorrectAnswersResponse(true, "Success", request.Test);
}
catch(Exception ex)
{
response = _responseFactory.CreateCorrectAnswersResponse(false, ex.Message);
}

return response;
}

public CorrectAnswersResponse GetCorrectAnswers(CorrectAnswersRequest request)
{
CorrectAnswersResponse response;

try
{
Domain.Entities.Test domain = _mapper.Map(request.Test);

domain = _testCorrector.CorrectTest(request.Test.Id, domain);

ContractTypes.Test service = _mapper.Map(domain);

response = _responseFactory.CreateCorrectAnswersResponse(true, "Success", service);
}
catch (Exception ex)
{
response = _responseFactory.CreateCorrectAnswersResponse(false, ex.Message);
}

return response;
}
}
}


CONTINUED IN NEXT POST
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 19 2016 04:23am
WCF SETUP
Code

namespace Correctamundo.Wcf
{
public class AutofacModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<ResponseFactory>().As<IResponseFactory>();
builder.RegisterType<TestCorrectorService>();
builder.RegisterType<TestMapper>().As<ITestMapper>();
builder.RegisterType<SectionMapper>().As<ISectionMapper>();
builder.RegisterType<QuestionMapper>().As<IQuestionMapper>();
}
}
}

namespace Correctamundo.Wcf
{
public class CorrectamundoServiceHostFactory : AutofacServiceHostFactory
{
public override System.ServiceModel.ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
{
ContainerBuilder builder = new ContainerBuilder();

Assembly[] assemblies = BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToArray();
builder.RegisterAssemblyModules(assemblies);
Container = builder.Build();

return base.CreateServiceHost(constructorString, baseAddresses);
}
}
}


WEB.CONFIG
Code

<?xml version="1.0" encoding="utf-8"?>
<configuration>

<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
<serviceActivations>
<add factory="Correctamundo.Wcf.CorrectamundoServiceHostFactory, Correctamundo" service="Correctamundo.Wcf.Services.Implementations.TestCorrectorService, Correctamundo" relativeAddress="TestCorrectorService.svc"/>
</serviceActivations>
</serviceHostingEnvironment>
<services>
<service name="Correctamundo.Wcf.Services.Implementations.TestCorrectorService">
<endpoint binding="basicHttpBinding" contract="Correctamundo.Wcf.Services.Interfaces.ITestCorrectorService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding>
<security mode="None">

</security>
</binding>
</basicHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
</system.webServer>

<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<dependentAssembly>

<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />

<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />

</dependentAssembly>

</assemblyBinding>

</runtime>
</configuration>



DOMAIN SETUP
Code

namespace Correctamundo.Domain
{
public class AutofacModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<TestRepository>().As<ITestRepository>().SingleInstance();
builder.RegisterType<TestCorrector>().As<ITestCorrector>();
}
}
}


CONTINUED IN NEXT POST
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 19 2016 04:25am
DOMAIN ENTITIES
Code

namespace Correctamundo.Domain.Entities
{
public class Question
{
public Question(string answer, bool correct)
{
if (string.IsNullOrEmpty(answer))
throw new ArgumentException("Answer cannot be null or empty");

Answer = answer;
IsCorrect = correct;
}

public string Answer { get; private set; }

public bool IsCorrect { get; private set; }

public Question CorrectQuestion(Question question)
{
string answer = string.Format("You marked: {0}. Correct Answer: {1}", question.Answer, Answer);
return new Question(answer, question.Answer.Equals(Answer));
}
}
}

namespace Correctamundo.Domain.Entities
{
public class Section
{
public Section(IEnumerable<Question> questions)
{
if (questions == null || !questions.Any())
throw new ArgumentException("Answers cannot be null or empty");
Questions = questions;
}

public IEnumerable<Question> Questions { get; private set; }

public Section CorrectSection(Section section)
{
return new Section(Questions.Zip(section.Questions, (answer, choice) => answer.CorrectQuestion(choice)));
}
}
}

namespace Correctamundo.Domain.Entities
{
public class Test
{
public Test(IEnumerable<Section> sections)
{
if (sections == null || !sections.Any())
throw new ArgumentException("Sections cannot be null or empty");
Sections = sections;
}

public IEnumerable<Section> Sections { get; internal set; }


public Test CorrectTest(Test test)
{
return new Test(Sections.Zip(test.Sections, (answer, choice) => answer.CorrectSection(choice)));
}
}
}




DOMAIN REPOSITORIES
Code

namespace Correctamundo.Domain.Repositories.Interfaces
{
public interface ITestRepository
{
Test GetTest(Guid id);
Guid AddTest(Test test);
}
}

namespace Correctamundo.Domain.Repositories.Implementations
{
public class TestRepository : ITestRepository
{
private readonly Dictionary<Guid, Test> _tests;
public TestRepository()
{
_tests = new Dictionary<Guid, Test>();
}

public Test GetTest(Guid id)
{
Test test = null;
if(!_tests.TryGetValue(id, out test))
throw new ArgumentException("Test does not exist");
return test;
}

public Guid AddTest(Test test)
{
if (test == null)
throw new ArgumentNullException("test");

Guid id = Guid.NewGuid();

_tests.Add(id, test);

return id;
}
}
}


DOMAIN SERVICES
Code

namespace Correctamundo.Domain.Services.Interfaces
{
public interface ITestCorrector
{
Guid AddTestKey(Test test);
Test CorrectTest(Guid id, Test test);
}
}

namespace Correctamundo.Domain.Services.Implementations
{
public class TestCorrector : ITestCorrector
{
private readonly ITestRepository _repository;

public TestCorrector(ITestRepository repository)
{
if (repository == null)
throw new ArgumentNullException("repository");

_repository = repository;
}


public Guid AddTestKey(Test test)
{
return _repository.AddTest(test);
}

public Test CorrectTest(Guid id, Test test)
{
Test key = _repository.GetTest(id);
return key.CorrectTest(test);
}
}
}
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 19 2016 04:27am
Using Autofac for DependencyInjection. Here is the packages.config for nuget

Code
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.5.2" targetFramework="net45" />
<package id="Autofac.Wcf" version="4.0.0" targetFramework="net45" />
</packages>



Hope this helps ;)
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 19 2016 09:51am
Quote (kdog3682 @ Feb 19 2016 10:48am)
Hey, thanks, it looks good. How do I run it though? Is there a website I go to?


Replying here so that everyone else interested has this information ;)

So, this is a WCF web service. You can locally host it under IIS. If you would like me to do this for you, I will have to charge you for the cost of a domain and a monthly maintenance fee. We can draw up a contract if you would like.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Feb 19 2016 02:22pm
Quote (Minkomonster @ Feb 19 2016 10:51am)
Replying here so that everyone else interested has this information ;)

So, this is a WCF web service. You can locally host it under IIS. If you would like me to do this for you, I will have to charge you for the cost of a domain and a monthly maintenance fee. We can draw up a contract if you would like.


Don't forget the standard 49.99$ one time activation fee. But maybe you can waive the recurring $2.91 energy surcharge if he's using an energy efficient server.
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 19 2016 02:29pm
Quote (carteblanche @ Feb 19 2016 03:22pm)
Don't forget the standard 49.99$ one time activation fee. But maybe you can waive the recurring $2.91 energy surcharge if he's using an energy efficient server.


As my business partner has pointed out, there may be some fine print.
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Feb 19 2016 04:02pm
could do this in python in a couple mins, sans the whole platform/input issue. How exactly are you receiving the answers to be graded? I don't know much about chromebooks, but I saw an addon for them (chrome) that lets you run python, but not sure how it works.
Go Back To Programming & Development Topic List
123Next
Add Reply New Topic New Poll