OnlineJudge

您所在的位置:网站首页 ccc是什么格式 OnlineJudge

OnlineJudge

#OnlineJudge| 来源: 网络整理| 查看: 265

      

       关于个人项目是在找实习以及参加秋招非常重要的简历内容,今天博主来介绍一下自己的一个项目。

开发环境:CentOS7、Makefile、g++、vscode、MySQL Workbench

所用技术:C++ STL 标准库、Boost 准标准库(字符串切割)、cpp-httplib 第三方开源网络库 、ctemplate 第三方开源前端网页渲染库、jsoncpp 第三方开源序列化、反序列化库、负载均衡设计、多进程、多线程(在这里没有实现)、MySQL C connect、Ace前端在线编辑器(了解) 、html/css/js/jquery/ajax (了解)

项目介绍:在 OnlineJudge 中,用户可以编写自己的代码,然后提交给后台,后台再根据负载情况选择合适的主机提供服务,这样就可以在自己搭建的项目中刷题了。

目录

项目整体介绍

项目代码

comm

util.hpp

log.hpp

compile_run_server

compile.hpp

run.hpp

compile_run.hpp

compile_run_server.cc

Makefile

oj_server

整体介绍

oj_model.hpp

oj_view.hpp

oj_control.hpp

oj_server.cc

conf/service_machine.conf

Makefile

Makefile

前端代码

wwwroot/index.html(首页)

template_html/all_questions.html

template_html/one_question.html

项目补充

项目演示

首页

题目列表

做题页面 

判题功能 

负载均衡测试

项目整体介绍

项目有三个核心模块:

comm:模块

compile_server:编译与运行模块

oj_server:获取题目列表,查看编写题目界面,负载均衡,其他功能

       客户端向发起请求,后端模块oj_server 首先获取用户请求,然后把请求交给后面对应的编译模块运行或者提供题目页面模块,把请求结果返回给客户端。

补充:

为什么要有oj_server模块?

        因为来自用户客户端的请求是多样化的,可能是编译运行请求;也有可能是获取首页请求等等。所以oj_server要对用户请求进行处理分析后,再把请求交给对应的后台主机进行处理,并把结果返回给用户。

oj_server是随机把客户端请求交给后台任意一个主机吗?

       不是,如果无脑式的请客户端大量请求交给后台主机,可能会导致资源分配不均的情况,比如一台主机正在处理大量请求,该主机资源都快被消耗完了,而其他主机还很悠闲似的,这种情况就极为不合理,这就是所说的"饥饿问题"。所以在oj_server模块里面设计一个算法能够根据主机负载情况选择当前主机负载最小的,并把任务交给它进行处理。

项目代码 comm util.hpp #pragma once #include #include #include #include #include #include #include //原子性递增计数器 #include #include #include namespace ns_util { const std::string temp_name = "./temp/"; //生成文件都在该目录下 class PathUtil { public: static std::string AddSuffix(const std::string& file_name, const std::string suffix) { std::string path_name = temp_name; path_name += file_name; path_name += suffix; return path_name; } //编译时需要的文件 //构建原文件: 路径 + 后缀的完整文件名 --> 要决定是那个路径下的文件 //前面路径仅仅是位置查找,不会混到文件名中,会自动找后面的文件名 //1234 -> ./temp/1234.cpp static std::string Src(const std::string& file_name) { return AddSuffix(file_name, ".cpp"); } static std::string Exe(const std::string& file_name) { return AddSuffix(file_name, ".exe"); } static std::string CompilerError(const std::string& file_name) { return AddSuffix(file_name, ".compiler_error"); } //运行时需要的文件 static std::string Stdin(const std::string& file_name) { return AddSuffix(file_name, ".stdin"); } static std::string Stdout(const std::string& file_name) { return AddSuffix(file_name, ".stdout"); } static std::string Stderr(const std::string& file_name) { return AddSuffix(file_name, ".stderr"); } }; class TimeUtil { public: static std::string GetTimeStamp() { struct timeval _time; //第一个参数是输出型参数 gettimeofday(&_time, nullptr); //第二个参数是时域,我们不用管 return std::to_string(_time.tv_sec);//只要s级别的,tv_usec微秒级别的不用管 } static std::string GetTimeMs() { struct timeval _time; gettimeofday(&_time, nullptr); return std::to_string(_time.tv_sec * 1000 + _time.tv_usec / 1000); } }; class FileUtil { public: static bool IsFileExists(const std::string& path_name) { struct stat st; //stat第二个参数是输出型参数,可以拿到该文件的属性 if(stat(path_name.c_str(), &st) == 0) //根据返回值来判断文件是否存在 { return true; } return false; } static std::string UniqFileName() { //毫秒级时间戳+原子性递增唯一值: 来保证唯一性 static std::atomic_uint id(0); id++; std::string ms = TimeUtil::GetTimeMs(); std::string uniq_id = std::to_string(id); return ms + "_" + uniq_id;//表示唯一的文件名 } static bool WriteFile(const std::string& target, const std::string& content) { std::ofstream out(target); if(!out.is_open()) { return false; } out.write(content.c_str()/*文件地址*/, content.size()); out.close(); return true; } static bool ReadFile(const std::string& target, std::string* content, bool keep = false) { (*content).clear(); std::ifstream in(target); if(!in.is_open()) { return false; } std::string line; while(getline(in, line)) { (*content) += line; (*content) += (keep ? "\n" : ""); } in.close(); return true; } }; class StringUtil { public: static void SplitString(std::string& str, std::vector* target, std::string sep) { //boost split boost::split(*target, str, boost::is_any_of(sep), boost::algorithm::token_compress_on); } }; } log.hpp #pragma once #include #include"util.hpp" namespace ns_log { using namespace ns_util; //日志等级 enum //匿名 { INFO, DEBUG, WARNING, ERROR, FATAL //系统出问题了 }; inline std::ostream& Log(const std::string& level, const std::string& file_name, int line) { //添加日志等级 std::string messege = "["; messege += level; messege += "]"; //添加报错文件名称 messege += "["; messege += file_name; messege += "]"; //添加报错行 messege += "["; messege += std::to_string(line); messege += "]"; //添加时间戳 messege += "["; messege += TimeUtil::GetTimeStamp(); messege += "]"; //cout本身是包含缓冲区的 std::cout 首页 题库 竞赛 讨论 求职 登录 欢迎来到我的OnlineJudge平台

这个是我独立开发的oj在线平台

点击我开始编程啦 template_html/all_questions.html 在线OJ-题目列表 /* 起手式, 百分百保证我们的样式设置可以不受默认影响 */ * { /* 消除网页的默认外边距 */ margin: 0px; /* 消除网页的默认内边距 */ padding: 0px; } html, body { width: 100%; height: 100%; } .container .navbar { width: 100%; height: 50px; background-color: black; /* 给父级标签设置overflow, 取消后序float带来的影响 */ overflow: hidden; } .container .navbar a { /* 设置a标签是行内块元素, 允许你设置宽度 */ display: inline-block; /* 设置a标签的宽度, a便签默认是行内元素, 无法设置宽度 */ width: 80px; /* 设置字体颜色 */ color: white; /* 设置字体的大小 */ font-size: large; /* 设置文字的高度,高度和导航栏一样 */ line-height: 50px; /* 去掉a标签的下划线 */ text-decoration: none; /* 设置a标签的文字居中 */ text-align: center; } /* 设置鼠标事件 */ .container .navbar a:hover { background-color: green; } .container .navbar .login{ float: right; } .container .question_list { padding-top: 50px; width: 800px; height: 100%; margin: 0px auto; /* background-color: #ccc; */ text-align: center; } .container .question_list table { width: 100%; font-size: large; font-family:Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif; margin-top: 50px; background-color: rgb(229, 235, 229); } .container .question_list h1 { color: green; } .container .question_list table .item { width: 100px; height: 40px; /* 5px是上下 auto是左右 */ /* padding-top: 10px auto; */ font-size: large; font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } .container .question_list table .item a { /* 去掉下划线 */ text-decoration: none; color: black; } .container .question_list table .item a:hover { color: blue; text-decoration: underline; } .container .footer { width: 100%; height: 50px; text-align: center; line-height: 50px; color: #ccc; } 首页 题库 竞赛 讨论 求职 登录 OnlineJudge题目列表 编号 标题 难度 {{#question_list}} {{number}}


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3