Laravelというフレームワークを使って既存のサービスを置き換えていました。

2022.08.09

Logging

おはようございます。今日は花火大会があるそうですが昼から雨が降るらしいのです。本当なのか信じられないほどの上天気です。

さて、現在、既存のサービス(WEBAPP)をLaravelへ置き換えているのですが、その置き換える中でLaravelは楽だなって思える所がありました、例えばページネーションはとても楽に設置出来たりログイン機能なども比較的楽に構築できる反面、データーベース、主にテーブルの操作は不便だなって思ったりしました。サブクエリなどを使用している箇所などはララベル用に置き換えないといけないので、既存のサービスを移植するのは、少し工数がかかります。

でも、いろいろな事がLaravelで構築すると楽というのが自分の総合評価なのですが、ゴリゴリコードを書くというよりは、ララベルのお作法に従って対応するというのが正しいかな。元々、Laravelにはいろいろな機能があるので、その機能を使用してコードを書くほうがベストだという事。

今ではググると日本語でのLaravelの解説もあるのでググった後に公式ドキュメントで例文を見てコードを修正するのがベストかなって思っています。

今まで頓挫していた開発も暇な時間を使い少しずつ 少しずつ作っていこうと思います。

タグ

Laravel, WEBAPP, いろいろ, クエリ, コード, サービス, サブ, データー, テーブル, ネーション, フレームワーク, ページ, ベース, ララベル, ログイン, 上天気, 不便, , , 今日, 作法, 使用, 反面, 大会, 対応, 少し, 工数, , 操作, 既存, , 本当, 構築, 機能, 現在, 移植, 箇所, 総合, 自分, 花火, 設置, 評価, ,

WebAPIの作り方、考え方です?。サンプルコードもありますよ。

2021.12.24

Logging

昨日から風邪を引いてしまいました…。今日も体調が優れない状態ですが、昨日よりはマシになっています、因みに風邪というよりも腸と胃に菌がはいってしまって、それによる発熱です?。

さて、今回はPHP言語でWebAPIの作りましたので、ご報告致します、どんなAPIかというと生年月日とカウントしたい歳をPOSTすると、現在の年齢、今まで生きてきた日数、カウント日数がレスポンス(返却)されます。

【JavaScript入門 #8】WebAPIを叩いてみよう!async await構文を使うと簡単!【ヤフー出身エンジニアの入門プログラミング講座】

PHPコードは下記の通りになります。適当に作ったので間違っている箇所があるかもしれませんが、そこはご愛嬌でお願いできますでしょうか?、また、WebAPIの叩き方はご自身でお考えくださいませ。
サーバーに負荷が増したらWEBAPIは閉じます。

尚、WEBAPIのURLはこちらになります。

https://zip358.com/api/age/v1/type1/

<?php
header('Access-Control-Allow-Origin: *');
date_default_timezone_set('Asia/Tokyo');
$birth_date = (string)$_POST["birth_date"];
$max_age = (int)$_POST["point_age"];

/**
 * @param string $birth_date
 * @return string|false
 */
function check1($birth_date = ""): bool
{
    $flg = false;
    $str_date = explode("/", $birth_date);
    if (count($str_date) === 3) {
        $flg = true;
        if (!((int)$str_date[0] >= 1000)) {
            $flg = false;
        }
        if(((int)$str_date[0] > (int)date("Y"))){
            $flg = false;
        }
        if (!((int)$str_date[1] >= 1 && (int)$str_date[1] <= 12)) {
            $flg = false;
        }
        if ($flg) {
            if ((int)$str_date[1] === 2) {
                if (!((int)$str_date[2] >= 1 && (int)$str_date[2] <= 28)) {
                    $flg = false;
                }
                if ((int)$str_date[0] % 4 === 0) {
                    $flg = true;
                    if (!((int)$str_date[2] >= 1 && (int)$str_date[2] <= 29)) {
                        $flg = false;
                    }
                    if ((int)$str_date[0] % 100 === 0) {
                        $flg = true;
                        if (!((int)$str_date[2] >= 1 && (int)$str_date[2] <= 28)) {
                            $flg = false;
                        }
                        if ((int)$str_date[0] % 400 === 0) {
                            $flg = true;
                            if (!((int)$str_date[2] >= 1 && (int)$str_date[2] <= 29)) {
                                $flg = false;
                            }
                        }
                    }
                }
            } else {
                $last_day = [4, 6, 9, 11];
                if (array_search((int)$str_date[1], $last_day, false)!== false) {
                    if (!((int)$str_date[2] >= 1 && (int)$str_date[2] <= 30)) {
                        $flg = false;
                    }
                } else {
                    if (!((int)$str_date[2] >= 1 && (int)$str_date[2] <= 31)) {
                        $flg = false;
                    }
                }
            }
        }
    }
    return $flg;
}

/**
 * @param int $age
 * @return string|false
 */
function check2($age = 0): bool
{
    $flg = true;
    if ($age < 0) {
        $flg = false;
    }
    return $flg;
}


/**
 * @param string $birth_date
 * @param string $maxage
 * @return string $reslut
 */
function sumup($birth_date, $maxage)
{
    $reslut = [];
    $birth_date_array = explode("/", $birth_date);
    $birth_date = sprintf("%04d%02d%02d", $birth_date_array[0], $birth_date_array[1], $birth_date_array[2]);
    $today = date('Ymd');
    $age = floor(($today - $birth_date) / 10000);
    $day1 = new DateTime("{$birth_date_array[0]}-{$birth_date_array[1]}-{$birth_date_array[2]}");
    $day2 = new DateTime();    
    $interval1 = $day1->diff($day2, true);
    $baseday =  (int)($interval1->format('%a'));
    if ((int)$maxage <= (int)$age) {
        $pointday = 0;
    } else {
        $maxage--;
        $day3 = new DateTime((date('Y') + ($maxage - $age)) . "-{$birth_date_array[1]}-{$birth_date_array[2]}");
        $interval2 = $day2->diff($day3, true);
        $pointday = (int)($interval2->format('%a'))+1;
    }


    $reslut = [
        [
            "result" => "success",
            "age"=>$age ."歳",
            "baseday" => $baseday . "日(生きてきた日数)",
            "pointday" => $pointday . "日(" .($maxage +1). "歳まであと)"
        ]
    ];
    return json_encode($reslut);
}

if (!check1($birth_date)) {
    print json_encode([
        [
            "result" => "error",
            "error" => "string is invalid1"
        ]
    ]);
} elseif (!check2($max_age)) {
    print json_encode([
        [
            "result" => "error",
            "error" => "string is invalid2"
        ]
    ]);
} else {
    print sumup($birth_date, $max_age);
}

タグ

39, Access-Control-Allow-Origin, API, header, lt, php, POST, url, WebApi, お願い, カウント, コード, こちら, ご報告, ご愛嬌, ご自身, サーバー, サンプル, そこ, それ, まし, レスポンス, 下記, 今回, 今日, 体調, 作り方, 叩き, 年齢, 日数, 昨日, , 状態, 現在, 生年月日, 発熱, 箇所, 考え方, , , , 言語, 負荷, 返却, 通り, 適当, 風邪,

TensorFlow Lite(テンソルフロー ライト)をインストールしモデル実行まで。

2021.06.14

Logging

ラズベリーパイ3にTensorFlow Lite(テンソルフロー ライト)をインストールしモデル実行まで軽く字幕で紹介した動画が下記になります。インストール方法は公式に書かれた通りに実行すれば上手くインストール出来るはずです。比較的に低スペックのマシンでも動くはずなのです、どうしてもエラーが出て動かないようであれば、それはおそらくあなたのマシンに問題があります?。

テンソルフローライト

動画でハマりどころがあるという事をブログで解説しますと書いていますので、そのハマりどころを解説します。。。

TensorFlow Lite(テンソルフロー ライト)で動かす場合、label_image.pyの修正箇所が公式に書かれていると思いますが・・・?、ここで自分がハマり、実行するコマンドを打ってもパラメーターがどうたらというエラーが出力されて動きませんでした。結論から言うと原因はマスターのソースコードにあったのです。修正を要領よく修正しては駄目だった。直接的な原因となったのは–num_threadsのパラメーターを投げていたのが原因でした。

公式では下記の内容に変更しなさいと書かれています。tf.lite.Interpreterの部分を置き換えればよいだろうと思っていたのです。

interpreter = tf.lite.Interpreter(model_path=args.model_file)

マスターのソースコードは若干、公式とは違ってこのようなソースコードになっていました。

  interpreter = tf.lite.Interpreter(
      model_path=args.model_file, num_threads=args.num_threads)

渡す引数が一つ増えていたので、自分はそれを残していたのですが・・・?、これでは動かないのです。そう・・num_threads=args.num_threadsは削除してあげないとモデルを動かすことが出来なかったのです。それがわからず渡すパラメーターが駄目なんだとか思って四苦八苦していました。

自分みたいな修正方法している方も中にはいると思ったので、今回、初心者がハマった沼を紹介しました?。

タグ

, image, label, LITE, py, tensorflow, あなた, インストール, エラー, コード, ここ, コマンド, スペック, ソース, それ, テンソル, はい, パス, パラメーター, フロー, ブログ, マシン, マスター, モデル, ライド, ラズベリー, 下記, , 修正, 公式, 出力, 動画, 原因, 問題, 場合, 字幕, 実行, 方法, 箇所, 紹介, 結論, 自分, 解説, 通り,

WordPressの公式ウィジェットカレンダー末日がズレている?ので直した。

2020.11.02

Logging

WordPressの公式ウィジェットカレンダー末日がズレている?ので直した。直した箇所はこちら変数名に$ooooと書いている部分が今回修正した箇所です。修正したファイルはWordPressのインクルードフォルダにある。ジェネラルテンプレートぴーえぃちーぴー(general-template.php)

wp-includes\general-template.php 

このファイルを直しました。コアファイルなので次期UPDATEで修正されるかとは思いますが、それまではこちらの修正でなんとかなるさ?!

因みに何故、$ooooにしたのかは、お???の???という土佐弁からです。ファイルの中にget_calendar(げっとカレンダー)という関数があるのでそちらを修正しています。原因は下記です。
gmdateというものを使用している所をローカルサーバーの時間で対応しました、さくらレンタルサーバーのタイムゾーンは日本時間を指しています。若干の誤差はあるけれど酷い誤差ではないのでdateで大丈夫そうです。

要は日付の末日が正確に取れていないことが原因みたいです?
はやく修正してくれることを願っています。

function get_calendar( $initial = true, $echo = true ) {
	global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;

	$key   = md5( $m . $monthnum . $year );
	$cache = wp_cache_get( 'get_calendar', 'calendar' );

	if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) {
		/** This filter is documented in wp-includes/general-template.php */
		$output = apply_filters( 'get_calendar', $cache[ $key ] );

		if ( $echo ) {
			echo $output;
			return;
		}

		return $output;
	}

	if ( ! is_array( $cache ) ) {
		$cache = array();
	}

	// Quick check. If we have no posts at all, abort!
	if ( ! $posts ) {
		$gotsome = $wpdb->get_var( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1" );
		if ( ! $gotsome ) {
			$cache[ $key ] = '';
			wp_cache_set( 'get_calendar', $cache, 'calendar' );
			return;
		}
	}

	if ( isset( $_GET['w'] ) ) {
		$w = (int) $_GET['w'];
	}
	// week_begins = 0 stands for Sunday.
	$week_begins = (int) get_option( 'start_of_week' );

	// Let's figure out when we are.
	if ( ! empty( $monthnum ) && ! empty( $year ) ) {
		$thismonth = zeroise( intval( $monthnum ), 2 );
		$thisyear  = (int) $year;
	} elseif ( ! empty( $w ) ) {
		// We need to get the month from MySQL.
		$thisyear = (int) substr( $m, 0, 4 );
		// It seems MySQL's weeks disagree with PHP's.
		$d         = ( ( $w - 1 ) * 7 ) + 6;
		$thismonth = $wpdb->get_var( "SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')" );
	} elseif ( ! empty( $m ) ) {
		$thisyear = (int) substr( $m, 0, 4 );
		if ( strlen( $m ) < 6 ) {
			$thismonth = '01';
		} else {
			$thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 );
		}
	} else {
		$thisyear  = current_time( 'Y' );
		$thismonth = current_time( 'm' );
	}

	$unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear );
	$last_day  = gmdate( 't', $unixmonth );
	$oooothisyear  = date( 'Y', $unixmonth  );
	$oooolast_day  = date( 't', $unixmonth );
	$oooothismonth = date( 'm' , $unixmonth);

	// Get the next and previous month and year with at least one post.
	$previous = $wpdb->get_row(
		"SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
		FROM $wpdb->posts
		WHERE post_date < '$thisyear-$thismonth-01'
		AND post_type = 'post' AND post_status = 'publish'
			ORDER BY post_date DESC
			LIMIT 1"
	);
	$next     = $wpdb->get_row(
		"SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
		FROM $wpdb->posts
		WHERE post_date > '$oooothisyear-$oooothismonth-{$oooolast_day} 23:59:59'
		AND post_type = 'post' AND post_status = 'publish'
			ORDER BY post_date ASC
			LIMIT 1"
	);

	/* translators: Calendar caption: 1: Month name, 2: 4-digit year. */
	$calendar_caption = _x( '%1$s %2$s', 'calendar caption' );
	$calendar_output  = '<table id="wp-calendar" class="wp-calendar-table">
	<caption>' . sprintf(
		$calendar_caption,
		$wp_locale->get_month( $thismonth ),
		gmdate( 'Y', $unixmonth )
	) . '</caption>
	<thead>
	<tr>';

	$myweek = array();

	for ( $wdcount = 0; $wdcount <= 6; $wdcount++ ) {
		$myweek[] = $wp_locale->get_weekday( ( $wdcount + $week_begins ) % 7 );
	}

	foreach ( $myweek as $wd ) {
		$day_name         = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd );
		$wd               = esc_attr( $wd );
		$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
	}

	$calendar_output .= '
	</tr>
	</thead>
	<tbody>
	<tr>';

	$daywithpost = array();

	// Get days with posts.
	$dayswithposts = $wpdb->get_results(
		"SELECT DISTINCT DAYOFMONTH(post_date)
		FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
		AND post_type = 'post' AND post_status = 'publish'
		AND post_date <= '{$oooothisyear}-{$oooothismonth}-{$oooolast_day} 23:59:59'",
		ARRAY_N
	);

	if ( $dayswithposts ) {
		foreach ( (array) $dayswithposts as $daywith ) {
			$daywithpost[] = (int) $daywith[0];
		}
	}

	// See how much we should pad in the beginning.
	$pad = calendar_week_mod( gmdate( 'w', $unixmonth ) - $week_begins );
	if ( 0 != $pad ) {
		$calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr( $pad ) . '" class="pad">?</td>';
	}

	$newrow      = false;
	$daysinmonth = (int) gmdate( 't', $unixmonth );
	$oooodaysinmonth = (int) date( 't', $unixmonth );

	for ( $day = 1; $day <= $oooodaysinmonth; ++$day ) {
		if ( isset( $newrow ) && $newrow ) {
			$calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
		}
		$newrow = false;

		if ( current_time( 'j' ) == $day &&
			current_time( 'm' ) == $thismonth &&
			current_time( 'Y' ) == $thisyear ) {
			$calendar_output .= '<td id="today">';
		} else {
			$calendar_output .= '<td>';
		}

		if ( in_array( $day, $daywithpost, true ) ) {
			// Any posts today?
			$date_format = gmdate( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) );
			/* translators: Post calendar label. %s: Date. */
			$label            = sprintf( __( 'Posts published on %s' ), $date_format );
			$calendar_output .= sprintf(
				'<a href="%s" aria-label="%s">%s</a>',
				get_day_link( $thisyear, $thismonth, $day ),
				esc_attr( $label ),
				$day
			);
		} else {
			$calendar_output .= $day;
		}

		$calendar_output .= '</td>';

		if ( 6 == calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
			$newrow = true;
		}
	}

	$pad = 7 - calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins );
	if ( 0 != $pad && 7 != $pad ) {
		$calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '">?</td>';
	}

	$calendar_output .= "\n\t</tr>\n\t</tbody>";

	$calendar_output .= "\n\t</table>";

	$calendar_output .= '<nav aria-label="' . __( 'Previous and next months' ) . '" class="wp-calendar-nav">';

	if ( $previous ) {
		$calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev"><a href="' . get_month_link( $previous->year, $previous->month ) . '">? ' .
			$wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) .
		'</a></span>';
	} else {
		$calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev">?</span>';
	}

	$calendar_output .= "\n\t\t" . '<span class="pad">?</span>';

	if ( $next ) {
		$calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next"><a href="' . get_month_link( $next->year, $next->month ) . '">' .
			$wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) .
		' ?</a></span>';
	} else {
		$calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next">?</span>';
	}

	$calendar_output .= '
	</nav>';

	$cache[ $key ] = $calendar_output;
	wp_cache_set( 'get_calendar', $cache, 'calendar' );

	if ( $echo ) {
		/**
		 * Filters the HTML calendar output.
		 *
		 * @since 3.0.0
		 *
		 * @param string $calendar_output HTML output of the calendar.
		 */
		echo apply_filters( 'get_calendar', $calendar_output );
		return;
	}
	/** This filter is documented in wp-includes/general-template.php */
	return apply_filters( 'get_calendar', $calendar_output );
}

タグ

calendar, general-template, GET, gmdate, oooo, php, UPDATE, WordPress, wp-includes, インクルード, ウィジェット, カレンダー, コア, こちら, サーバー, さくら, ジェネラル, ズレ, そちら, それまで, タイム, テンプレート, ファイル, フォルダ, もの, レンタル, ローカル, 下記, , 今回, 使用, 修正, 公式, 原因, 土佐弁, 変数, 対応, , 時間, 末日, 次期, 箇所, 部分, 関数,

7つの習慣(人格主義の回復)があまり楽しくないけど『はっ』とする。

2017.03.18

Logging


『7つの習慣(人格主義の回復)』があまり楽しくないけど(固い)『はっ』とする。
まだ1%としか読んでいないけれど、『はっ』とした点は、
ものの見方の所ですね、みんな客観的に物事を見ていると思い込んでいる。
それは間違っていないけれど、皆、自分から見た視点で客観的に物事を見ているだけで
他人の目になって物事を見ているひとは少ない。
大体の人が自分視点で客観的に見て他人を評価したりしている。
他人目線で客観的に見る事が
出来るかのかが、結構重要になるとのこと。
ちなみに、この本の重要な箇所は太字で強調されていますので
時間がない方は太字で書かれた前後を読んで理解したほうが早そうです。
次に紹介する本はちょっと前に読んだ本です(会社の社長の席にちらっと置いていた本です)。
タイトルに惹かれて、電子書籍で購入しました。
『なぜ、あなたのウェブには戦略がないのか?』
一番気になったのは、最初に書かれていた企業戦略の部分ですね、
読んでいてリスクを踏んで企業成長をせよと
書かれていませんでしたが、未来に投資せよ、その為には
長期的なリスクは必要という
前向きな経営戦略論共に成功例が書かれていました。
そのことに関しては感想は省略します(逃)。
 


 
 
 
 

タグ

ウェブ, タイトル, ひとは, リスク, 人格主義, 他人, 他人目線, 企業成長, 企業戦略, 前向き, 回復, 太字, , 物事, 箇所, 経営戦略論共に成功例, 習慣, 見方, , 電子書籍,

大阪の観光地へ行ってきた!!

2016.10.12

Logging

先日、大阪の観光地を巡ってきました。
どこもコミコミなので人混みに酔うひとは要注意。
三連休の中休みともあって混み具合はまぁまぁ混んでいた方だと
思います。今回、巡った箇所は通天閣、道頓堀、心斎橋、かに道楽とかです。
この中で要注意があるとすれば、通天閣の展望台へいくことです。
女子同士とか男同士とかで行くと「まじでぇ?」って事になるので
必ず、男女混合かカップルで行くことをおすすめします。
まぁ行けばわかります。
ちなみにお気に入りの景色は、道頓堀だったりします。
なんか良かったです。
大阪は今回で3回目ぐらいしか足を運んでいないのですが
一つ気付いた事が・・・
電車が東京の電車に比べて横揺れが少ない・・・なっていう感じがしました。
なんか電車の乗り心地が良いなって思いました。
東京と高知の汽車を比べると断然、東京のほうが乗り心地は良いです。
東京は本数が多い分、時刻に合わすためガンガンいこうぜ!
って具合になっている感じがしますが、大阪は安全重視ぽっい気がしましたね。
最後にiPhoneで撮影した写真を載せときます。

タグ

, iPhone, おすすめ, お気に入り, カップル, かに道楽, こと, コミコミ, ため, どこ, ひと, まし, 一つ, 三連, , 中休み, 乗り心地, , 人混み, 今回, , 先日, 具合, , 同士, 大阪, 女子, 安全, 展望台, 心斎橋, 感じ, , 時刻, 景色, 最後, 本数, 東京, 横揺れ, , 汽車, 注意, 混合, 男同士, 男女, 箇所, 観光地, , 通天閣, 道頓堀, 重視, 電車, 高知,