2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,8 +1,12 @@
;Task:
Write a simple tool to track a small set of data.
The tool should have a commandline interface to enter at least two different values.
The tool should have a command-line interface to enter at least two different values.
The entered data should be stored in a structured format and saved to disk.
It does not matter what kind of data is being tracked. It could be your CD collection, your friends birthdays, or diary.
It does not matter what kind of data is being tracked.   It could be a collection (CDs, coins, baseball cards, books), a diary, an electronic organizer (birthdays/anniversaries/phone numbers/addresses), etc.
You should track the following details:
* A description of the item. (e.g., title, name)
@ -10,14 +14,23 @@ You should track the following details:
* A date (either the date when the entry was made or some other date that is meaningful, like the birthday); the date may be generated or entered manually
* Other optional fields
<br>
The command should support the following [[Command-line arguments]] to run:
* Add a new entry
* Print the latest entry
* Print the latest entry for each category
* Print all entries sorted by a date
<br>
The category may be realized as a tag or as structure (by making all entries in that category subitems)
The file format on disk should be human readable, but it need not be standardized. A natively available format that doesn't need an external library is preferred. Avoid developing your own format however if you can use an already existing one. If there is no existing format available pick one of: [[JSON]], [[S-Expressions]], [[YAML]], or [[wp:Comparison_of_data_serialization_formats|others]].
The file format on disk should be human readable, but it need not be standardized. &nbsp; A natively available format that doesn't need an external library is preferred. &nbsp; Avoid developing your own format if you can use an already existing one. &nbsp; If there is no existing format available, pick one of:
:::* &nbsp; [[JSON]]
:::* &nbsp; [[S-Expressions]]
:::* &nbsp; [[YAML]]
:::* &nbsp; [[wp:Comparison_of_data_serialization_formats|others]]
See also [[Take notes on the command line]] for a related task.
;Related task:
* &nbsp; [[Take notes on the command line]]
<br><br>

View file

@ -0,0 +1,81 @@
function db
{
[CmdletBinding(DefaultParameterSetName="None")]
[OutputType([PSCustomObject])]
Param
(
[Parameter(Mandatory=$false,
Position=0,
ParameterSetName="Add a new entry")]
[string]
$Path = ".\SimpleDatabase.csv",
[Parameter(Mandatory=$true,
ParameterSetName="Add a new entry")]
[string]
$Name,
[Parameter(Mandatory=$true,
ParameterSetName="Add a new entry")]
[string]
$Category,
[Parameter(Mandatory=$true,
ParameterSetName="Add a new entry")]
[datetime]
$Birthday,
[Parameter(ParameterSetName="Print the latest entry")]
[switch]
$Latest,
[Parameter(ParameterSetName="Print the latest entry for each category")]
[switch]
$LatestByCategory,
[Parameter(ParameterSetName="Print all entries sorted by a date")]
[switch]
$SortedByDate
)
if (-not (Test-Path -Path $Path))
{
'"Name","Category","Birthday"' | Out-File -FilePath $Path
}
$db = Import-Csv -Path $Path | Foreach-Object {
$_.Birthday = $_.Birthday -as [datetime]
$_
}
switch ($PSCmdlet.ParameterSetName)
{
"Add a new entry"
{
[PSCustomObject]@{Name=$Name; Category=$Category; Birthday=$Birthday} | Export-Csv -Path $Path -Append
}
"Print the latest entry"
{
$db[-1]
}
"Print the latest entry for each category"
{
($db | Group-Object -Property Category).Name | ForEach-Object {($db | Where-Object -Property Category -Contains $_)[-1]}
}
"Print all entries sorted by a date"
{
$db | Sort-Object -Property Birthday
}
Default
{
$db
}
}
}
db -Name Bev -Category friend -Birthday 3/3/1983
db -Name Bob -Category family -Birthday 7/19/1987
db -Name Gill -Category friend -Birthday 12/9/1986
db -Name Gail -Category family -Birthday 2/11/1986
db -Name Vince -Category family -Birthday 3/10/1960
db -Name Wayne -Category coworker -Birthday 5/29/1962

View file

@ -0,0 +1 @@
db

View file

@ -0,0 +1 @@
db -Latest

View file

@ -0,0 +1 @@
db -LatestByCategory

View file

@ -0,0 +1 @@
db -SortedByDate