Added custom Blogposts for ProblemEulerBefunge
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
* @property string $Date
|
||||
* @property string $Title
|
||||
* @property string $Content
|
||||
* @property string $ControllerID
|
||||
* @property string $Visible
|
||||
* @property string $Enabled
|
||||
*/
|
||||
@@ -29,10 +30,10 @@ class BlogPost extends CActiveRecord
|
||||
// NOTE: you should only define rules for those attributes that
|
||||
// will receive user inputs.
|
||||
return array(
|
||||
array('Date, Title, Content, Visible, Enabled', 'required'),
|
||||
array('Date, Title, Content, ControllerID, Visible, Enabled', 'required'),
|
||||
array('Visible, Enabled', 'numerical', 'integerOnly'=>true),
|
||||
|
||||
array('ID, Date, Title, Content, Visible, Enabled', 'safe', 'on'=>'search'),
|
||||
array('ID, Date, Title, Content, ControllerID, Visible, Enabled', 'safe', 'on'=>'search'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -57,6 +58,7 @@ class BlogPost extends CActiveRecord
|
||||
'Date' => 'Date',
|
||||
'Title' => 'Title',
|
||||
'Content' => 'Content',
|
||||
'ControllerID' => 'ControllerID',
|
||||
'Visible' => 'Visible',
|
||||
'Enabled' => 'Enabled',
|
||||
);
|
||||
@@ -82,6 +84,7 @@ class BlogPost extends CActiveRecord
|
||||
$criteria->compare('Date',$this->Date,true);
|
||||
$criteria->compare('Title',$this->Title,true);
|
||||
$criteria->compare('Content',$this->Content,true);
|
||||
$criteria->compare('ControllerID',$this->ControllerID,true);
|
||||
$criteria->compare('Visible',$this->Visible,true);
|
||||
$criteria->compare('Enabled',$this->Enabled,true);
|
||||
|
||||
@@ -167,4 +170,9 @@ class BlogPost extends CActiveRecord
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function isSpecialBlogPost()
|
||||
{
|
||||
return ! empty($this->ControllerID);
|
||||
}
|
||||
}
|
||||
|
||||
177
www/protected/models/EulerProblem.php
Normal file
177
www/protected/models/EulerProblem.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This is the model class for table "{{eulerproblem}}".
|
||||
*
|
||||
* The followings are the available columns in table '{{eulerproblem}}':
|
||||
* @property integer $Problemnumber
|
||||
* @property string $Problemtitle
|
||||
* @property string $Problemdescription
|
||||
* @property string $Code
|
||||
* @property string $Explanation
|
||||
* @property integer $AbbreviatedCode
|
||||
* @property string $SolutionSteps
|
||||
* @property string $SolutionTime
|
||||
* @property string $SolutionWidth
|
||||
* @property string $SolutionHeight
|
||||
* @property string $SolutionValue
|
||||
*/
|
||||
class EulerProblem extends CActiveRecord
|
||||
{
|
||||
const TIMELEVEL_PERFECT = 0;
|
||||
const TIMELEVEL_GOOD = 1;
|
||||
const TIMELEVEL_OK = 2;
|
||||
const TIMELEVEL_BAD = 3;
|
||||
const TIMELEVEL_FAIL = 4;
|
||||
|
||||
/**
|
||||
* @return string the associated database table name
|
||||
*/
|
||||
public function tableName()
|
||||
{
|
||||
return '{{eulerproblem}}';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array validation rules for model attributes.
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
// NOTE: you should only define rules for those attributes that
|
||||
// will receive user inputs.
|
||||
return array(
|
||||
array('Problemnumber, Problemtitle, Problemdescription, Code, Explanation, AbbreviatedCode, SolutionSteps, SolutionTime, SolutionWidth, SolutionHeight, SolutionValue', 'required'),
|
||||
array('AbbreviatedCode', 'numerical', 'integerOnly'=>true),
|
||||
array('SolutionSteps, SolutionTime, SolutionValue', 'length', 'max'=>20),
|
||||
array('Problemtitle', 'length', 'max'=>50),
|
||||
|
||||
array('Problemnumber, Problemtitle, Problemdescription, Code, Explanation, AbbreviatedCode, SolutionSteps, SolutionTime, SolutionValue', 'safe', 'on'=>'search'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array relational rules.
|
||||
*/
|
||||
public function relations()
|
||||
{
|
||||
// NOTE: you may need to adjust the relation name and the related
|
||||
// class name for the relations automatically generated below.
|
||||
return array(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array customized attribute labels (name=>label)
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return array(
|
||||
'Problemnumber' => 'Problemnumber',
|
||||
'Problemtitle' => 'Problemtitle',
|
||||
'Problemdescription' => 'Problemdescription',
|
||||
'Code' => 'Code',
|
||||
'Explanation' => 'Explanation',
|
||||
'AbbreviatedCode' => 'Abbreviated Code',
|
||||
'SolutionSteps' => 'Solution Steps',
|
||||
'SolutionTime' => 'Solution Time',
|
||||
'SolutionWidth' => 'Solution Width',
|
||||
'SolutionHeight' => 'Solution Height',
|
||||
'SolutionValue' => 'Solution Value',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of models based on the current search/filter conditions.
|
||||
*
|
||||
* Typical usecase:
|
||||
* - Initialize the model fields with values from filter form.
|
||||
* - Execute this method to get CActiveDataProvider instance which will filter
|
||||
* models according to data in model fields.
|
||||
* - Pass data provider to CGridView, CListView or any similar widget.
|
||||
*
|
||||
* @return CActiveDataProvider the data provider that can return the models
|
||||
* based on the search/filter conditions.
|
||||
*/
|
||||
public function search()
|
||||
{
|
||||
$criteria=new CDbCriteria;
|
||||
|
||||
$criteria->compare('Problemnumber',$this->Problemnumber);
|
||||
$criteria->compare('Problemtitle',$this->Problemdescription,true);
|
||||
$criteria->compare('Problemdescription',$this->Problemdescription,true);
|
||||
$criteria->compare('Code',$this->Code,true);
|
||||
$criteria->compare('Explanation',$this->Explanation,true);
|
||||
$criteria->compare('AbbreviatedCode',$this->AbbreviatedCode);
|
||||
$criteria->compare('SolutionSteps',$this->SolutionSteps,true);
|
||||
$criteria->compare('SolutionTime',$this->SolutionTime,true);
|
||||
$criteria->compare('SolutionWidth',$this->SolutionWidth);
|
||||
$criteria->compare('SolutionHeight',$this->SolutionHeight);
|
||||
$criteria->compare('SolutionValue',$this->SolutionValue,true);
|
||||
|
||||
return new CActiveDataProvider($this, array(
|
||||
'criteria'=>$criteria,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the static model of the specified AR class.
|
||||
* Please note that you should have this exact method in all your CActiveRecord descendants!
|
||||
* @param string $className active record class name.
|
||||
* @return EulerProblem the static model class
|
||||
*/
|
||||
public static function model($className=__CLASS__)
|
||||
{
|
||||
return parent::model($className);
|
||||
}
|
||||
|
||||
public function getSourcecodefile($absolute = true)
|
||||
{
|
||||
return ($absolute ? '/' : '') . 'data/blog/Befunge/Euler_Problem-' . str_pad($this->Problemnumber, 3, '0', STR_PAD_LEFT) . '.b93';
|
||||
}
|
||||
|
||||
public function getTimeScore()
|
||||
{
|
||||
if ($this->SolutionTime < 100) // < 100ms
|
||||
return EulerProblem::TIMELEVEL_PERFECT;
|
||||
|
||||
else if ($this->SolutionTime < 15 * 1000) // < 5s
|
||||
return EulerProblem::TIMELEVEL_GOOD;
|
||||
|
||||
else if ($this->SolutionTime < 60 * 1000) // < 1min
|
||||
return EulerProblem::TIMELEVEL_OK;
|
||||
|
||||
else if ($this->SolutionTime < 5 * 60 * 1000) // < 5min
|
||||
return EulerProblem::TIMELEVEL_BAD;
|
||||
|
||||
else
|
||||
return EulerProblem::TIMELEVEL_FAIL;
|
||||
}
|
||||
|
||||
public function isBefunge93()
|
||||
{
|
||||
return $this->SolutionWidth <= 80 AND $this->SolutionHeight <= 25;
|
||||
}
|
||||
|
||||
public function generateMarkdown()
|
||||
{
|
||||
$num_padded = str_pad($this->Problemnumber, 3, '0', STR_PAD_LEFT);
|
||||
|
||||
return
|
||||
'Problem [' . $num_padded. '](http://projecteuler.net/problem=' . $num_padded . '): ' . $this->Problemtitle . PHP_EOL .
|
||||
'--------' . PHP_EOL .
|
||||
'' . PHP_EOL .
|
||||
MsHelper::encloseLines($this->Problemdescription, '> ', '') . PHP_EOL .
|
||||
'' . PHP_EOL .
|
||||
'```befunge' . PHP_EOL .
|
||||
$this->Code . PHP_EOL .
|
||||
'```' . PHP_EOL .
|
||||
'[Download](/data/blog/Befunge/Euler_Problem-' . $num_padded . '.b93)' . PHP_EOL .
|
||||
'' . PHP_EOL .
|
||||
$this->Explanation . PHP_EOL .
|
||||
'' . PHP_EOL .
|
||||
'**Interpreter steps:** `' . number_format($this->SolutionSteps, 0, null, ',') . '` ' . PHP_EOL .
|
||||
'**Execution time** ([BefunExec](/programs/view/BefunGen)): `' . number_format($this->SolutionTime, 0, null, ',') . '` ms' . (($this->SolutionTime < 1000) ? (' ') : (' *(= ' . MsHelper::formatMilliseconds($this->SolutionTime) . ')* ')) . PHP_EOL .
|
||||
'**Program size:** `' . $this->SolutionWidth . 'x' . $this->SolutionHeight . '` ' . PHP_EOL .
|
||||
'**Solution:** `' . number_format($this->SolutionValue, 0, null, ',') . '` ';
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,6 @@ class HighscoreEntries extends CActiveRecord
|
||||
array('PLAYER, IP', 'length', 'max'=>41),
|
||||
array('CHECKSUM', 'length', 'max'=>32),
|
||||
// The following rule is used by search().
|
||||
// @todo Please remove those attributes that should not be searched.
|
||||
array('GAME_ID, POINTS, PLAYER, PLAYERID, CHECKSUM, TIMESTAMP, IP', 'safe', 'on'=>'search'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,8 +81,6 @@ class HighscoreGames extends CActiveRecord
|
||||
*/
|
||||
public function search()
|
||||
{
|
||||
// @todo Please modify the following code to remove attributes that should not be searched.
|
||||
|
||||
$criteria=new CDbCriteria;
|
||||
|
||||
$criteria->compare('ID',$this->ID);
|
||||
|
||||
Reference in New Issue
Block a user