Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item stats #73

Merged
merged 13 commits into from
Oct 6, 2023
66 changes: 61 additions & 5 deletions src/app/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ class Item extends Model
protected $appends = [
'DescriptionLang',
'CompletionStatus',
'TranscriptionText',
'Properties'
'Transcription',
'Properties',
'EditStart',
'Places',
'Persons'
];

public function htrData()
Expand Down Expand Up @@ -99,14 +102,15 @@ public function getCompletionStatusAttribute()
/**
* Get the current version of Item Transcription
*/
public function getTranscriptionTextAttribute()
public function getTranscriptionAttribute()
{
if ($this->TranscriptionSource === 'manual') {
$manualTranscription = $this
->hasMany(Transcription::class, 'ItemId')
->select('UserId', 'TextNoTags as TranscriptionText', 'CurrentVersion')
->firstWhere('CurrentVersion', 1);

return $manualTranscription ? $manualTranscription->TextNoTags : '';
return $manualTranscription ? $manualTranscription : [];
}

if ($this->TranscriptionSource === 'htr') {
Expand All @@ -118,7 +122,35 @@ public function getTranscriptionTextAttribute()
->latest()
->first();

return $latest ? $latest->htrDataRevision->pluck('TranscriptionText')->first() : '';
return $latest ? $latest->htrDataRevision->first() : [];
}

return [];
}

/**
* Get the timestamp od first transcription
*/
public function getEditStartAttribute()
{
if ($this->TranscriptionSource === 'manual') {
$dateStart = $this
->hasMany(Transcription::class, 'ItemId')
->orderBy('Timestamp', 'asc')
->pluck('Timestamp')
->first();

return $dateStart ? $dateStart : '';
}

if ($this->TranscriptionSource === 'htr') {
$dateStart = $this
->hasMany(HtrData::class, 'ItemId')
->orderBy('Timestamp', 'asc')
->pluck('Timestamp')
->first();

return $dateStart ? $dateStart : '';
}

return '';
Expand All @@ -141,4 +173,28 @@ public function getPropertiesAttribute()

return $plucked;
}

/**
* Get the Item places
*/
public function getPlacesAttribute()
{
$places = $this
->hasMany(Place::class, 'ItemId')
->get();

return $places ? $places : [];
}

/**
* Get the Item persons
*/
public function getPersonsAttribute()
{
$persons = $this
->hasMany(Person::class, 'ItemId')
->get();

return $persons ? $persons : [];
}
}
30 changes: 30 additions & 0 deletions src/app/Models/Person.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Person extends Model
{
/**
* Use user defined exisiting timestamp columns
*/
const CREATED_AT = null;
const UPDATED_AT = null;

/**
* The table associated with the model.
*
* Config over convention here to respect exsting table names.
*
* @var string
*/
protected $table = 'Person';

/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'PersonId';
}
30 changes: 30 additions & 0 deletions src/app/Models/Place.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Place extends Model
{
/**
* Use user defined exisiting timestamp columns
*/
const CREATED_AT = null;
const UPDATED_AT = null;

/**
* The table associated with the model.
*
* Config over convention here to respect exsting table names.
*
* @var string
*/
protected $table = 'Place';

/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'PlaceId';
}
4 changes: 3 additions & 1 deletion src/app/Models/Transcription.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ class Transcription extends Model
* @var string
*/
protected $primaryKey = 'TranscriptionId';
}

protected $casts = ['CurrentVersion' => 'boolean'];
}
2 changes: 1 addition & 1 deletion src/storage/api-docs/api-docs.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.3

info:
version: 1.18.0
version: 1.19.0
title: Transcribathon Platform API v2
description: This is the documentation of the Transcribathon API v2 used by [https:transcribathon.eu](https://transcribathon.eu/).<br />
For authorization you can use the the bearer token you are provided with.
Expand Down
42 changes: 37 additions & 5 deletions src/storage/api-docs/items-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,43 @@ ItemsAdditionalDataReferenceSchema:

ItemsAdditionalGetReferenceSchema:
properties:
TranscriptionText:
type: string
nullable: true
description: plain text of the current selected transcription (of source manual or HTR)
example: Plain text representation oft the transcription data
Transcription:
type: object
properties:
TranscriptionText:
type: string
nullable: true
description: plain text of the current selected transcription (of source manual or HTR)
example: Plain text representation oft the transcription data
UserId:
type: integer
description: the ID of the user of this transcription
example: 1392
CurrentVersion:
type: integer
description: determine if this is the current/active transcription (only if transcription is manual)
example: 1
HtrDataId:
type: integer
description: ID of the HTR data entry (only if HTR data)
example: 2
Timestamp:
type: string
description: Time of creation of the HTR transcription (only if HTR data)
example: '2022-02-23T09:57:03.000000Z'
LastUpdated:
type: string
description: Time of last update of the HTR transcription (only if HTR data)
example: '2022-02-23T09:57:03.000000Z'
TranscriptionData:
type: string
nullable: true
description: HTR data data as XML string (only if HTR data)
example: '<?xml version="1.0" encoding="UTF-8"? />'
HtrDataRevisionId:
type: integer
description: ID of the HTR data revision entry (only if HTR data)
example: 2

PropertiesReference:
type: array
Expand Down
Loading