オークションで一眼レフ落札したら、フィルムカメラだった!

エンジニアたるもの、写真の意識が高くないと駄目だ、とあるカメラやってる方にインスパイアーされ、ヤフオクで一眼レフを落札

ワクワク^^

届きました。

いいね~この重厚感

あれ、ちょっと待て、これフィルム?

普通そこ間違えるかね。。

といいつつ、速攻でフィルムと電池を買ってしまった。

息抜きに写真でも撮りに行きますかね。

決算ir情報をphpで翻訳する

yahoo 譲渡制限付株式報酬としての新株式の発行に関するお知らせ(259文字)
当社は中長期的かつ持続的な企業価値の向上を目指しており、そのためには、将来の成長を見据えた
サービスへの先行投資や設備投資、資本業務提携を積極的に行うことが重要だと認識しています。同時
に、利益還元を通じて株主の皆さまに報いることが上場会社としての責務と捉えています。
上記方針のもと、当期の期末配当金につきましては、1 株当たり8.86 円(配当金総額は504 億円)と
いたしました。
当社はこれからも、将来の成長のための投資を継続しながら、株主の皆さまへの適切な利益還元を行
うことにより、企業価値の向上を目指していきます。

$key = 'hoge';

$host = "https://api.cognitive.microsofttranslator.com";
$path = "/translate?api-version=3.0";
$params = "&to=en";
$text = "当社は中長期的かつ持続的な企業価値の向上を目指しており、そのためには、将来の成長を見据えた
サービスへの先行投資や設備投資、資本業務提携を積極的に行うことが重要だと認識しています。同時
に、利益還元を通じて株主の皆さまに報いることが上場会社としての責務と捉えています。
上記方針のもと、当期の期末配当金につきましては、1 株当たり8.86 円(配当金総額は504 億円)と
いたしました。
当社はこれからも、将来の成長のための投資を継続しながら、株主の皆さまへの適切な利益還元を行
うことにより、企業価値の向上を目指していきます。";

if(!function_exists('com_create_guid')){
	function com_create_guid(){
		return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
		mt_rand(0, 0xffff), mt_rand(0, 0xffff),
		mt_rand(0, 0xffff),
		mt_rand(0, 0x0fff) | 0x4000,
		mt_rand(0, 0x3fff) | 0x8000,
		mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
	}
}

function Translate ($host, $path, $key, $params, $content) {
    $headers = "Content-type: application/json\r\n" .
        "Content-length: " . strlen($content) . "\r\n" .
        "Ocp-Apim-Subscription-Key: $key\r\n" .
        "X-ClientTraceId: " . com_create_guid() . "\r\n";
    $options = array (
        'http' => array (
            'header' => $headers,
            'method' => 'POST',
            'content' => $content
        )
    );
    $context  = stream_context_create($options);
    $result = file_get_contents ($host . $path . $params, false, $context);
    return $result;
}

$requestBody = array (
    array (
        'Text' => $text,
    ),
);
$content = json_encode($requestBody);
$result = Translate($host, $path, $key, $params, $content);

$json = json_decode($result);
echo $json[0]->translations[0]->text;

echoの結果->565文字
—–
We aim to improve our corporate value in the medium to long term and We recognize that it is important to actively engage in upfront investment in services, capital investment, and business alliances. Same , it is our duty as a listed company to repay our shareholders through the return of profits. Under the above policy, the year-end dividend for the current period is 8.86 yen per share (total dividend of 50.4 billion yen) We. We will continue to invest in future growth and to return appropriate profits to our shareholders. We aim to improve corporate value.

悪くない!というか、金融系に強い帰国子女に頼むよりも質が高く、早くて安い(笑)
これは自動化したい。

月200万文字まで無料なので、1000文字の翻訳だとすると、上限2000回か。
全銘柄のEdinet IR自動翻訳だとちょっとキツイな。
うーん、どうする?

Azure Translator Text APIを使ってphpで翻訳する

file_get_contentsしたjsonをdecodeします。

$key = 'hogehoge';

$host = "https://api.cognitive.microsofttranslator.com";
$path = "/translate?api-version=3.0";
$params = "&to=en";
$text = "1文をバラバラにして単語レベルで翻訳をするのではなく、1文をひとまとめにして翻訳";

if(!function_exists('com_create_guid')){
	function com_create_guid(){
		return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
		mt_rand(0, 0xffff), mt_rand(0, 0xffff),
		mt_rand(0, 0xffff),
		mt_rand(0, 0x0fff) | 0x4000,
		mt_rand(0, 0x3fff) | 0x8000,
		mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
	}
}

function Translate ($host, $path, $key, $params, $content) {
    $headers = "Content-type: application/json\r\n" .
        "Content-length: " . strlen($content) . "\r\n" .
        "Ocp-Apim-Subscription-Key: $key\r\n" .
        "X-ClientTraceId: " . com_create_guid() . "\r\n";
    $options = array (
        'http' => array (
            'header' => $headers,
            'method' => 'POST',
            'content' => $content
        )
    );
    $context  = stream_context_create($options);
    $result = file_get_contents ($host . $path . $params, false, $context);
    return $result;
}

$requestBody = array (
    array (
        'Text' => $text,
    ),
);
$content = json_encode($requestBody);
$result = Translate($host, $path, $key, $params, $content);


$json = json_decode($result);
echo $json[0]->translations[0]->text;

これは。。。

eminem lose yourself
——-
Look, if you had one shot, one opportunity
To seize everything you ever wanted
One moment
Would you capture it or just let it slip?
Yo
His palms are sweaty, knees weak, arms are heavy
There’s vomit on his sweater already, mom’s spaghetti
He’s nervous, but on the surface he looks calm and ready
To drop bombs, but he keeps on forgettin’
What he wrote down, the whole crowd goes so loud
He opens his mouth, but the words won’t come out
He’s chokin’, how, everybody’s jokin’ now
The clocks run out, times up, over, blaow!
Snap back to reality, oh there goes gravity
Oh, there goes Rabbit, he choked
He’s so mad, but he won’t give up that easy? No
He won’t have it, he knows his whole back city’s ropes
It don’t matter,
He’s dope,…

ラップの翻訳って難しいと思うが、
結果

ほお

翻訳のアルゴリズムは?

前:ルールベース翻訳や統計翻訳
->文法や単語などのルールを一つ一つ登録して翻訳

後:ニューラルネットワーク
->1文をバラバラにして単語レベルで翻訳をするのではなく、1文をひとまとめにして翻訳

そうなのか、VoiceTraとかも統計翻訳の機械学習かと思ってた。。
NICT(情報通信研究機構)
http://www.nict.go.jp/
ここは興味ある。金融庁以来。

しかし予算500億も使ってんのかよ。。コロプラの売上高と一緒じゃんか。。ちくしょー羨ましすぎる。。
https://www.nict.go.jp/pdf/business-report-2016.pdf

ibm translator

使ってみる。

[vagrant@localhost translator]$ curl -u "username":pass" \
> -H "Accept: application/json" \
> "https://gateway.watsonplatform.net/language-translator/api/v2/translate?model_id=en-ja&text=ibm+translator"
{
  "translations" : [ {
    "translation" : "IBM変換プログラム"
  } ],
  "word_count" : 2,
  "character_count" : 14
}

幾つか試したが、レスポンスがなかったり、tokyo -> “translation” : “統教” と精度がイマイチだったり。。。
やってることは凄いんだろうけど、これ以上深堀りする気ナシ。

IBM developerWorks

IBMって、どうなんでしょう?
勝屋さんが元IBMのVCですよね。

とりあえず、翻訳系のサービスが作りたい。
っま、動かしながら考えましょう。

watson APIs Language Translator

The IBM Watson Language Translator service converts text input in one language into a destination language for the end user using background from domain-specific models. Translation is available among Arabic, Chinese (Simplified and Traditional), English, French, Portuguese, German, Spanish, Dutch, Turkish, Russian, Korean, Italian and Polish (some languages may not be available for all domains).

日本語 原文

現在、我が国では、IT投資が活発化するとともに、グローバルな事業展開が一層の拡大傾向にあります。一方で、先端IT技術を活用した新しいビジネスモデルへの需要が高まっています。企業に対しても、持続可能な社会の実現を見据えた投資によってイノベーションを発揮し、事業を通じた社会課題の解決に積極的に取り組んでいくことが求められています。

watson 翻訳結果(英語)
想像以上に悪くない気がする。。

In Japan, IT investment is becoming more active, and global business expansion is becoming more and more expanding.On the other hand, there is a growing demand for new business models using cutting-edge IT technologies.It is also necessary for companies to exert innovation through investment that is a view to realizing a sustainable society, and to actively work on solving social issues through business.

あああああああああああああああああ
Japanese からは Englishしかないいいいいいいいいいいい
というか、英語以外は、ほとんど英語への翻訳しかないですね。

tableの背景色を縞々にする

偶数なら tr:nth-child(even)、奇数なら tr:nth-child(odd)で指定します。

#table tr:nth-child(even) { 
   background-color: #ECECEC;
  }

PC版

SP版

大分見た目が良くなった(笑)

さあ、次は、ドメインを取得して、Vagrant -> VPSのサーバー側の構築。
バーチャルホスト、mongoDB、php mongoDBドライバーのインストールまでは何も問題なく終了。

trafficの分類

document.referrerで取得したURLにRegular Expressionで該当すればフラグを立てたい。

1.Organic Search
https://www.google.co.jp
https://www.bing.com/
https://www.yahoo.co.jp/
https://www.msn.com/ja-jp/
http://www.baidu.com/

2.Social
https://www.facebook.com/
https://twitter.com/?lang=ja
https://www.instagram.com/?hl=ja
https://line.me/ja/

3.Direct

4.Referral

早速書いてみる。

$url = "ttps://www.google.co.jp/search?q=%E6%A9%9F%E6%A2%B0%E5%AD%A6%E7%BF%92&oq=%E6%A9%9F%E6%A2%B0%E5%AD%A6%E7%BF%92&aqs=chrome..69i57j69i61l3j0l2.3764j0j7&sourceid=chrome&ie=UTF-8";
if(preg_match("/www.google/", $url)){
  $channel = "Organic Search"; 
  $media = "google";
} else{
  $channel = "else";
}
echo $channel;

項目を増やします。yahooはco.jpもcomも検索時に、https://search.yahoo.comとサブドメインにsearchが付きます。(分かり易い!)

$url = "http://hpscript.com/ip/";
if(empty($url)){
  $channel = "Direct"; 
}elseif(preg_match("/www.google/", $url)){
  $channel = "Organic Search"; 
  $media = "google";
}elseif(preg_match("/www.bing/", $url)){
  $channel = "Organic Search"; 
  $media = "bing";
}elseif(preg_match("/search.yahoo/", $url)){
  $channel = "Organic Search"; 
  $media = "yahoo";
}elseif(preg_match("/www.baidu/", $url)){
  $channel = "Organic Search"; 
  $media = "baidu";
}elseif(preg_match("/www.facebook/", $url)){
  $channel = "Social"; 
  $media = "facebook";
}elseif(preg_match("/twitter/", $url)){
  $channel = "Social"; 
  $media = "twitter";
}elseif(preg_match("/www.instagram/", $url)){
  $channel = "Social"; 
  $media = "twitter";
}elseif(preg_match("/line/", $url)){
  $channel = "Social"; 
  $media = "line";
}else{
  $channel = "Referral";
}
echo $channel;

doubleclick.php(js受け取り)のphpで処理を書いていきます。

if(!is_null($data["acquisition"])){
	$url = $data["acquisition"];
	if(empty($url)){
	  $channel = "Direct"; 
	  $media = "(not set)";
	}elseif(preg_match("/www.google/", $url)){
	  $channel = "Organic Search"; 
	  $media = "google";
	}elseif(preg_match("/www.bing/", $url)){
	  $channel = "Organic Search"; 
	  $media = "bing";
	}elseif(preg_match("/search.yahoo/", $url)){
	  $channel = "Organic Search"; 
	  $media = "yahoo";
	}elseif(preg_match("/www.baidu/", $url)){
	  $channel = "Organic Search"; 
	  $media = "baidu";
	}elseif(preg_match("/www.facebook/", $url)){
	  $channel = "Social"; 
	  $media = "facebook";
	}elseif(preg_match("/twitter/", $url)){
	  $channel = "Social"; 
	  $media = "twitter";
	}elseif(preg_match("/www.instagram/", $url)){
	  $channel = "Social"; 
	  $media = "twitter";
	}elseif(preg_match("/line/", $url)){
	  $channel = "Social"; 
	  $media = "line";
	}else{
	  $channel = "Referral";
	  $media = $url;
	}
	$data = $data + array('channel'=>$channel, 'media'=>$media);
}

directの場合は、mediaは(not set)

urlがbingにマッチしたら、channelはorganic searchになります。

mongoDBにも入っています。

つづいて、データを入れてanalytics側のviewをつくっていきます。
organic, social, direct, refferalの分類はchart.jsを使いたい。

OK!!!!!!!!!!!!!!!!!!!!!!!
リファクタリングして、次はスタイリングです!
今回はweb fontを使って、fontにもこだわりたい。