Skip to content

Instantly share code, notes, and snippets.

@ten9miq
Last active September 12, 2024 09:37
Show Gist options
  • Save ten9miq/5af25a487b1aeb4035c8e8898f4ba6fd to your computer and use it in GitHub Desktop.
Save ten9miq/5af25a487b1aeb4035c8e8898f4ba6fd to your computer and use it in GitHub Desktop.
param (
[string]$inputFile
)
# 入力ファイルの存在を確認
if (-Not (Test-Path $inputFile)) {
Write-Host "Error: ファイル $inputFile が見つかりません。" -ForegroundColor Red
exit 1
}
# 出力ファイル名を作成
$outputFile = Join-Path -Path (Split-Path $inputFile -Parent) -ChildPath ("output_" + (Split-Path $inputFile -Leaf))
# CSVファイルの読み込み
$csvData = Import-Csv -Path $inputFile
# 結果を格納するリスト
$result = @()
# 各行を処理
foreach ($row in $csvData) {
$id_value = $row.ID
$other_info = $row.'他の情報'
# 作業時間列を処理
foreach ($col in $csvData | Get-Member -MemberType Properties | Where-Object { $_.Name -like '作業時間*' }) {
$time_data = $row.$($col.Name)
if ($time_data) {
# 作業時間の内容を分割
$split_data = $time_data -split ';'
$comment = $split_data[0]
$start_time = $split_data[1]
$user_account = $split_data[2]
$elapsed_time = $split_data[3]
# 新しいレコードを作成
$newRow = [PSCustomObject]@{
'ID' = $id_value
'コメント' = $comment
'開始日時' = $start_time
'ユーザーアカウント' = $user_account
'経過秒数' = $elapsed_time
'他の情報' = $other_info
}
# 結果に追加
$result += $newRow
}
}
}
# 新しいデータをCSVとして出力
$result | Export-Csv -Path $outputFile -NoTypeInformation
Write-Host "処理が完了しました。出力ファイル: $outputFile" -ForegroundColor Green
param (
[string]$inputFile
)
# 入力ファイルの存在を確認
if (-Not (Test-Path $inputFile)) {
Write-Host "Error: ファイル $inputFile が見つかりません。" -ForegroundColor Red
exit 1
}
# 出力ファイル名を作成
$outputFile = Join-Path -Path (Split-Path $inputFile -Parent) -ChildPath ("output_" + (Split-Path $inputFile -Leaf))
# CSVファイルの読み込み
$csvData = Import-Csv -Path $inputFile
# 結果を格納するリスト
$result = @()
# 各行を処理
foreach ($row in $csvData) {
$id_value = $row.ID
$other_info = $row.'他の情報'
# 作業時間列を処理
foreach ($col in $csvData.PSObject.Properties.Name | Where-Object { $_ -like '作業時間*' }) {
$time_data = $row.$col
if ($time_data) {
# 作業時間の内容を分割
$split_data = $time_data -split ';'
$comment = $split_data[0]
$start_time = $split_data[1]
$user_account = $split_data[2]
$elapsed_time = $split_data[3]
# 新しいレコードを作成
$newRow = [PSCustomObject]@{
'ID' = $id_value
'コメント' = $comment
'開始日時' = $start_time
'ユーザーアカウント' = $user_account
'経過秒数' = $elapsed_time
'他の情報' = $other_info
}
# 結果に追加
$result += $newRow
}
}
}
# 新しいデータをCSVとして出力
$result | Export-Csv -Path $outputFile -NoTypeInformation
Write-Host "処理が完了しました。出力ファイル: $outputFile" -ForegroundColor Green
param (
[string]$inputFile
)
# 入力ファイルの存在を確認
if (-Not (Test-Path $inputFile)) {
Write-Host "Error: ファイル $inputFile が見つかりません。" -ForegroundColor Red
exit 1
}
# 入力ファイルのフルパスを取得
$inputFileFullPath = Resolve-Path $inputFile
Write-Host "Full input file path: $inputFileFullPath" -ForegroundColor Yellow
# 出力ファイル名を作成
$outputFile = Join-Path -Path (Split-Path $inputFileFullPath -Parent) -ChildPath ("output_" + (Split-Path $inputFileFullPath -Leaf))
Write-Host "Output file path: $outputFile" -ForegroundColor Yellow
# CSVファイルの読み込み
$csvData = Import-Csv -Path $inputFileFullPath
Write-Host "CSV data loaded. Total rows: $($csvData.Count)" -ForegroundColor Yellow
# 全列名の確認
Write-Host "All columns:" -ForegroundColor Yellow
$columns = $csvData[0].PSObject.Properties.Name
foreach ($col in $columns) {
Write-Host "Column name: '$col'" -ForegroundColor Cyan
}
# 列名のフィルタリングと確認
Write-Host "Checking column names that match '作業時間*' after trimming..." -ForegroundColor Yellow
foreach ($col in $columns | Where-Object { $_.Trim() -like '作業時間*' }) {
Write-Host "Column found: '$col'" -ForegroundColor Green
}
# 結果を格納するリスト
$result = @()
# 各行を処理
foreach ($row in $csvData) {
Write-Host "Current Row: $($row | Format-Table | Out-String)" -ForegroundColor Yellow
$id_value = $row.ID
$other_info = $row.'他の情報'
Write-Host "Processing ID: $id_value" -ForegroundColor Yellow
# 作業時間列を処理
foreach ($col in $columns | Where-Object { $_.Trim() -like '作業時間*' }) {
$time_data = $row.$($col)
Write-Host "Column being processed: '$($col)'" -ForegroundColor Blue
if ($null -ne $time_data -and $time_data.Trim() -ne "") {
Write-Host "Data in '$($col)': $time_data" -ForegroundColor Cyan
# 作業時間の内容を分割
$split_data = $time_data -split ';'
Write-Host "Split data: $($split_data -join ', ')" -ForegroundColor Green
Write-Host "Split data count: $($split_data.Count)" -ForegroundColor Green
if ($split_data.Count -eq 4) {
$comment = $split_data[0]
$start_time = $split_data[1]
$user_account = $split_data[2]
$elapsed_time = $split_data[3]
# 新しいレコードを作成
$newRow = [PSCustomObject]@{
'ID' = $id_value
'コメント' = $comment
'開始日時' = $start_time
'ユーザーアカウント' = $user_account
'経過秒数' = $elapsed_time
'他の情報' = $other_info
}
# 結果に追加
$result += $newRow
Write-Host "Added new row to result: $($newRow | Out-String)" -ForegroundColor Green
} else {
Write-Host "Warning: 作業時間列のデータが正しく分割されませんでした。Split data count: $($split_data.Count)" -ForegroundColor Red
}
} else {
Write-Host "No valid data found in column: '$($col)'" -ForegroundColor Magenta
}
}
}
# 新しいデータをCSVとして出力
if ($result.Count -gt 0) {
$csvContent = $result | ConvertTo-Csv -NoTypeInformation | Out-String
[System.IO.File]::WriteAllText($outputFile, $csvContent, [System.Text.Encoding]::GetEncoding("Shift_JIS"))
Write-Host "処理が完了しました。出力ファイル: $outputFile" -ForegroundColor Green
} else {
Write-Host "Error: 出力データがありませんでした。" -ForegroundColor Red
}
@ten9miq
Copy link
Author

ten9miq commented Aug 15, 2024

ID,作業時間1,作業時間2,他の情報
1,"コメント1;2024-08-01 09:00;user1;3600","コメント2;2024-08-01 10:00;user2;1800","データ1"
2,"コメント3;2024-08-02 09:00;user1;7200",,"データ2"

@ten9miq
Copy link
Author

ten9miq commented Aug 27, 2024

SET @target_date = '2024-08-26 14:00:00'; -- 例として2024年8月26日14時を指定

SELECT *
FROM schedules
WHERE
(month_set IS NULL OR FIND_IN_SET(MONTH(@target_date), month_set)) AND
(week_of_month IS NULL OR
(week_of_month = '第一週' AND WEEK(@target_date, 1) = WEEK(DATE_FORMAT(@target_date, '%Y-%m-01'), 1)) OR
(week_of_month = '第二週' AND WEEK(@target_date, 1) = WEEK(DATE_FORMAT(@target_date, '%Y-%m-01'), 1) + 1) OR
(week_of_month = '第三週' AND WEEK(@target_date, 1) = WEEK(DATE_FORMAT(@target_date, '%Y-%m-01'), 1) + 2) OR
(week_of_month = '第四週' AND WEEK(@target_date, 1) = WEEK(DATE_FORMAT(@target_date, '%Y-%m-01'), 1) + 3) OR
(week_of_month = '最終週' AND WEEK(@target_date, 1) = WEEK(LAST_DAY(@target_date), 1))
) AND
(week_set IS NULL OR FIND_IN_SET(DAYNAME(@target_date), week_set)) AND
(specific_date IS NULL OR DATE(@target_date) = specific_date) AND
(day IS NULL OR DAY(@target_date) = day) AND
hour = HOUR(@target_date);

@ten9miq
Copy link
Author

ten9miq commented Sep 2, 2024

#!/bin/bash

# 入力ファイルの指定
input_file="input.txt"
# 出力ファイルの指定(既存の内容は削除される)
output_file="output.txt"

# 出力ファイルを初期化
> "$output_file"

# テキストファイルを1行ずつ読み込む
while IFS= read -r line
do
  # 空行をスキップ
  if [ -z "$line" ]; then
    continue
  fi
  
  # セパレートのための区切り線と検索情報を書き込む
  echo "=============================" >> "$output_file"
  echo "検索文字列: $line" >> "$output_file"
  echo "実行コマンド: find . -name \"$line\"" >> "$output_file"
  echo "=============================" >> "$output_file"
  
  # Findコマンドを実行し、その結果を追記
  find . -name "$line" >> "$output_file"
  
  # 検索の終了を示すために追加の区切り線を追加
  echo "=============================" >> "$output_file"
  echo "" >> "$output_file"  # 改行を追加
done < "$input_file"

@ten9miq
Copy link
Author

ten9miq commented Sep 9, 2024

<?php
function getNthWeekday($date) {
    // 指定された日付のDateTimeオブジェクトを作成
    $dateObj = new DateTime($date);
    
    // 指定された日付の曜日を取得 (0:日曜日, 6:土曜日)
    $weekday = $dateObj->format('w');

    // 今月の1日のDateTimeオブジェクトを作成
    $firstDayOfMonth = new DateTime($dateObj->format('Y-m-01'));

    // カウンターを初期化
    $count = 0;

    // 1日から指定された日付までループして曜日をカウント
    for ($i = 1; $i <= $dateObj->format('j'); $i++) {
        $currentDay = new DateTime($dateObj->format('Y-m-') . $i);
        if ($currentDay->format('w') == $weekday) {
            $count++;
        }
    }

    return $count;
}

// 使用例
$date = '2024-08-27'; // 例えば、8月27日が何回目の火曜日か
echo "その月の" . getNthWeekday($date) . "回目の曜日です。\n";
?>

@ten9miq
Copy link
Author

ten9miq commented Sep 10, 2024

2024/1/11
2024/2/6
2024/3/28
2024/4/28
2024/5/10
2024/6/4
2024/7/17
2024/8/9
2024/9/14
2024/10/14
2024/11/16
2024/12/26

@ten9miq
Copy link
Author

ten9miq commented Sep 10, 2024

3, 6, 8, 9, 10, 11, 12
2, 4, 6, 10, 11, 12
3, 4, 5, 7, 8, 12
3, 4, 5, 7, 8, 9
1, 5, 6, 8, 9, 11, 12
1, 2, 5, 7, 9, 11
4, 8, 11
1, 3, 7, 8, 9, 11
5, 8, 10, 11
1, 2, 6, 8, 11, 12

@ten9miq
Copy link
Author

ten9miq commented Sep 10, 2024

1, 3, 4, 7, 8, 11, 12
1, 2, 4, 6, 9
1, 2, 3, 4, 7, 11
1, 2, 3, 5, 6, 7, 9, 10, 11, 12
2, 3, 8
3, 6, 10
1, 2, 5, 8, 10, 11
2, 3, 5, 6, 7, 11
2, 4, 5, 6, 8, 9, 10, 11, 12
2, 6, 8, 10, 12

@ten9miq
Copy link
Author

ten9miq commented Sep 10, 2024

木曜日, 火曜日, 月曜日, 金曜日, 水曜日, 土曜日, 日曜日
月曜日, 火曜日
月曜日, 金曜日, 日曜日, 火曜日, 土曜日
水曜日, 火曜日, 日曜日, 月曜日, 金曜日, 土曜日, 木曜日
月曜日
月曜日, 木曜日, 水曜日, 金曜日, 日曜日
火曜日, 木曜日, 日曜日, 土曜日
日曜日
日曜日
火曜日, 土曜日, 月曜日, 水曜日, 金曜日, 日曜日

@ten9miq
Copy link
Author

ten9miq commented Sep 12, 2024

$weekday_map = [
    '月曜' => 'Monday',
    '火曜' => 'Tuesday',
    '水曜' => 'Wednesday',
    '木曜' => 'Thursday',
    '金曜' => 'Friday',
    '土曜' => 'Saturday',
    '日曜' => 'Sunday',
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment