using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Globalization;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Windows.Shapes;
namespace Phistory
{
class IndexCanvas:Canvas
{
private static readonly DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
///
/// 現在画面に表示されている目盛りを検索するためのDictionary
///
private Dictionary Up2NowIndexLabelDictionary { get; set; }
private Dictionary Up2NowIndexRectangleDictionary { get; set; }
private BitmapImage line = new BitmapImage(new Uri("images/line.bmp", UriKind.Relative));
public IndexCanvas()
{
Up2NowIndexLabelDictionary = new Dictionary();
CultureResources.ResourceProvider.DataChanged += OnResourceProviderDataChanged;
}
public void Render(long time, long scale)
{
// 表示開始タイマー刻み数(100ナノ秒単位)
long begin = time;
// 表示終了タイマー刻み数(100ナノ秒単位)
long end = time + (long)(ActualWidth * scale);
//目盛りの更新処理
Dictionary nextIndexLabelDictionary = new Dictionary();
Dictionary nextIndexRectangleDictionary = new Dictionary();
List indicesToBeAdded = new List();
foreach (Index index in GetIndices(begin, end, scale))
{
if (!Up2NowIndexLabelDictionary.ContainsKey(index))//今回表示すべき目盛りでこれまでも表示されていなかった目盛りに対する処理
{
indicesToBeAdded.Add(index);
}
else//前回から表示されている目盛りに対する処理
{
double x = (index.Time - time) / scale;
SetLeft(Up2NowIndexRectangleDictionary[index], x);
SetLeft(Up2NowIndexLabelDictionary[index], x);
nextIndexRectangleDictionary.Add(index, Up2NowIndexRectangleDictionary[index]);
nextIndexLabelDictionary.Add(index, Up2NowIndexLabelDictionary[index]);
}
}
foreach (Index index in indicesToBeAdded)
{
double x = (index.Time - time) / scale;
Rectangle lineRect = new Rectangle();
lineRect.Width = 1;
lineRect.Height = 24;
SolidColorBrush brush = new SolidColorBrush(Util.GetForegroundColor());
lineRect.Fill = brush;
SetLeft(lineRect, x);
SetBottom(lineRect, 0);
Children.Add(lineRect);
nextIndexRectangleDictionary.Add(index, lineRect);
Label label = new Label();
label.Content = index.Text;
label.FontSize = 20;
label.Foreground = new SolidColorBrush(Util.GetForegroundColor());
SetLeft(label, x);
Children.Add(label);
nextIndexLabelDictionary.Add(index, label);
}
List indicesToBeRemoved = new List();
foreach (Index index in Up2NowIndexLabelDictionary.Keys)
{
if (!nextIndexLabelDictionary.ContainsKey(index))//これまで表示されてきた目盛りで今回表示しない目盛りに対する処理
{
indicesToBeRemoved.Add(index);
}
}
foreach (Index index in indicesToBeRemoved)
{
Children.Remove(Up2NowIndexLabelDictionary[index]);
Children.Remove(Up2NowIndexRectangleDictionary[index]);
}
Up2NowIndexRectangleDictionary = nextIndexRectangleDictionary;
Up2NowIndexLabelDictionary = nextIndexLabelDictionary;
}
private void OnResourceProviderDataChanged(object sender, EventArgs args)
{
foreach (Index index in Up2NowIndexRectangleDictionary.Keys)
{
Rectangle lineRect = Up2NowIndexRectangleDictionary[index];
if (Children.Contains(lineRect))
{
Children.Remove(lineRect);
}
}
foreach (Index index in Up2NowIndexLabelDictionary.Keys)
{
Label label = Up2NowIndexLabelDictionary[index];
if (Children.Contains(label))
{
Children.Remove(label);
}
}
Up2NowIndexRectangleDictionary.Clear();
Up2NowIndexLabelDictionary.Clear();
}
///
/// 現在の表示範囲属性で画面に表示する目盛り情報を取得します。
///
///
private List GetIndices(long begin, long end, long scale)
{
List retIndices = new List();
string format;
long interval = 0;//目盛りの間隔
if (scale < 25920000000)
{
if (scale < 2000000)// 40s/200px
{
format = "HH:mm:ss";
if (scale < 500000)// 10s/200px
{
interval = 50000000; // 5s
}
else if (scale < 2000000)
{ // 40s/200px
interval = 200000000; // 20s
}
}
else if (scale < 360000000)
{ // 2h/200px
format = "HH:mm";
if (scale < 6000000)
{ // 2m/200px
interval = 600000000; // 60s
}
else if (scale < 30000000)
{ // 10m/200px
interval = 3000000000; // 5m
}
else if (scale < 120000000)
{ //
interval = 12000000000;
}
else if (scale < 360000000)
{
interval = 36000000000;
}
}
else if (scale < 2160000000)
{
format = "dd HH:mm";
interval = 216000000000;
}
else
{
format = Util.GetMonthDateString();
if (scale < 8640000000)
{
interval = 864000000000;
}
else
{
interval = 2592000000000;
}
}
for (int i = 0; i < (int)((end - begin) / interval) + 2; i++)
{
DateTime date = new DateTime(begin - begin % interval + i * interval);
Index indexElement = new Index(date.Ticks, date.ToString(format));
retIndices.Add(indexElement);
}
}
else if (scale < 60480000000)//1week/100px
{
format = Util.GetMonthDateString();
interval = 864000000000;
for (int i = 0; i < (int)((end - begin) / interval) + 2; i++)
{
DateTime date = new DateTime(begin - begin % interval + i * interval);
if (date.DayOfWeek == DayOfWeek.Sunday)
{
Index indexElement = new Index(date.Ticks, date.ToString(format));
retIndices.Add(indexElement);
}
}
}
else if (scale < 725760000000)
{
format = Util.GetYearMonthString();
DateTime date = new DateTime(begin);
date = date.AddDays(-date.Day + 1);
date = date.AddHours(-date.Hour);
date = date.AddMinutes(-date.Minute);
date = date.AddSeconds(-date.Second);
date = date.AddMilliseconds(-date.Millisecond);
while (date.Ticks < end)
{
Index indexElement = new Index(date.Ticks, date.ToString(format));
if (scale < 241920000000)
{
retIndices.Add(indexElement);
}
else
{
if ((date.Month - 1) % 3 == 0)
{
retIndices.Add(indexElement);
}
}
date = date.AddMonths(1);
}
}
else
{
format = "yyyy";
DateTime date = new DateTime(begin);
date = date.AddMonths(-date.Month + 1);
date = date.AddDays(-date.Day + 1);
date = date.AddHours(-date.Hour);
date = date.AddMinutes(-date.Minute);
date = date.AddSeconds(-date.Second);
date = date.AddMilliseconds(-date.Millisecond);
while (date.Ticks < end)
{
Index indexElement = new Index(date.Ticks, date.ToString(format));
if (scale < 3153600000000)
{
retIndices.Add(indexElement);
}
else
{
if (date.Year % 5 == 0)
{
retIndices.Add(indexElement);
}
}
date = date.AddYears(1);
}
}
return retIndices;
}
}
}
2018年12月26日水曜日
コード
2018年7月17日火曜日
ひらがなかけ算九九
ひらがなを少しずつ読み始めた娘。
読めることが楽しいようで外を歩いていても看板にひらがながあると読み始める。
この意欲を有効活用するために掛け算九九をひらがなだけで作成した。
するとあら不思議、とりあえずひらがなを読みまくっていただけなのにいつの間にかいくつかは音として覚えてしまい、そのうち掛け算の概念も理解できてしまうのです。
下記URLがGoogleドライブに保存した掛け算九九一覧表です。印刷して壁に貼ってご利用ください。
https://docs.google.com/document/d/10rOZgZ2aIMBquW2hxH7Xmh8vGcC89N6-CvOPzlfFF7Y/edit?usp=sharing
読めることが楽しいようで外を歩いていても看板にひらがながあると読み始める。
この意欲を有効活用するために掛け算九九をひらがなだけで作成した。
するとあら不思議、とりあえずひらがなを読みまくっていただけなのにいつの間にかいくつかは音として覚えてしまい、そのうち掛け算の概念も理解できてしまうのです。
下記URLがGoogleドライブに保存した掛け算九九一覧表です。印刷して壁に貼ってご利用ください。
https://docs.google.com/document/d/10rOZgZ2aIMBquW2hxH7Xmh8vGcC89N6-CvOPzlfFF7Y/edit?usp=sharing
![]() |
2018年4月24日火曜日
Google Cloud Storage(GCS)に大量のファイルをアップロードする方法
機械学習に使うデータセットとか大量のデータをGCSにアップロードする場合はちゃんとした方法でアップロードしないと遅すぎて1月経っても終わらなかったりする。
GCSのドキュメント( https://cloud.google.com/storage/docs/object-basics?hl=ja )には
アップロード方法としてコンソール, GSUTIL, コードサンプル, REST APIの4通りの方法が記載されているがこのうちコンソール, GSUTIL, コードサンプル(python)について試して速度を見てみた。
その結果
コードサンプル(python) >> GSUTIL > コンソール
でした。
アップロードするならコードサンプル(python)がおススメです。
なお、pythonの場合コードサンプルは
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print('File {} uploaded to {}.'.format(
source_file_name,
destination_blob_name))
となっているが注意する点は
- from google.cloud import storage をすること。
- コードサンプル中のbucket_nameには"gs://mybucket"の場合は"mybucket"を設定すること。
- コードサンプル中のdestination_blob_nameには"gs://mybucket/floder1/myfile.jpg"の場合は"floder1/myfile.jpg"を設定すること。
2018年4月4日水曜日
CentOS 7 64bit にOpenCVをインストールする。
自分の環境だとlibopencv_core.so.3.4.1のlinkの時にDSO missingとかundefined reference to symbolとか言われて困った。
結局cmakeコマンドに引数でコンパイラを指定していたのだがそこにg++を指定すべきだったのがgccをしていたのが原因だった。LinuxでC言語系開発した経験がなかったのが遠因。
(もう一つの原因は自分でgccの7.3をソースからビルドして/usr/localの下にinstallしてしまったのが事。これがデフォルトになってしまうと現状では結構文句言われてしまいかなり後悔している。)
誤:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/gcc ..
正:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++ ..
ソース
https://github.com/opencv/opencv/issues/5435
結局cmakeコマンドに引数でコンパイラを指定していたのだがそこにg++を指定すべきだったのがgccをしていたのが原因だった。LinuxでC言語系開発した経験がなかったのが遠因。
(もう一つの原因は自分でgccの7.3をソースからビルドして/usr/localの下にinstallしてしまったのが事。これがデフォルトになってしまうと現状では結構文句言われてしまいかなり後悔している。)
誤:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/gcc ..
正:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++ ..
ソース
https://github.com/opencv/opencv/issues/5435
登録:
コメント (Atom)
