socketref,再见!高德

https://github.com/adoggie

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  246 Posts :: 4 Stories :: 312 Comments :: 0 Trackbacks

常用链接

留言簿(54)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

#

有些dbi2的数据库实现了fetchoneDict接口,毕竟不是强制要求的,但是实际应用中非常有用


import
 sys,sqlite3,os
def fetchoneDict(cr):
    ff 
= [ r[0] for r in cr.description ]
    rr 
= cr.fetchone()
    
if rr:
        
return dict( zip(ff,rr)  )
    
return {}

cnn 
=  sqlite3.connect('e:/tax.db3')
print dir(sqlite3)
cr 
= cnn.execute('select * from core_bill')

while 1:
    r 
= fetchoneDict(cr)
    
if not r: break
    
print r
posted @ 2011-12-29 01:34 放屁阿狗 阅读(393) | 评论 (0)编辑 收藏

在应用项目中,我们又很多用户信息点需要被加载到图层上,这些点可以使用CustomMarker来显示。用户点分布密集程度不一致,而且量很大,一次性的全部加载进行图层是不可取的,幸好使用的是openscales的wmsc图层,底图是瓦片(tile)形式加载,所以最简单的方式就是当tile加载和释放的时候通知到用户层,用户层实现加载和释放用户信息点。
看了一下openscales的代码,发现tile的申请和释放并没有通知到层对象,所以我们不能直接获取这些事件消息。
wmsc类层次结构: wmsc->wms->Grid->HttpRequest->Layer
Grid类维护了瓦片集合的二维数组,当地图extent改变时,openscales将扫描Grid的瓦片数组,如果发现有空洞则调用wms的addTile()创建新的tile,如果发现可废弃tile,则调用Grid.removeExcessTiles()。
addTile()之后openscales将通知layer接收TileEvent.TILE_LOAD_START事件,这个TILE_LOAD_START事件是可以利用的,作为tile加载时的通知事件,在使用的wmsc层时添加一个事件侦听便可获取tile加载事件;
ImageTile从Tile派生下来,当Grid作废无效Tile时,将调用Tile.destroy()方法,所以我在TileEvent添加新事件TILE_DESTROY,在Tile.destroy()通知layer获取tile销毁的消息
 1         public function destroy():void {
 2             if (this.layer!=null){
 3                 this.layer.dispatchEvent(new TileEvent(TileEvent.TILE_DESTROY,this));
 4             }
 5             this.layer = null;
 6             this.bounds = null;
 7             this.size = null;
 8             this.position = null;
10         }
修改文件 TileEvent.as,Tile.as
好了,事件接收只需要在Layer的实例添加如下代码:
addEventListener(TileEvent.TILE_LOAD_START,tileLoadHandler);
addEventListener(TileEvent.TILE_DESTROY,tileDestroyHandler);
TileEvent.tile携带了tile的boundle信息可供我们去请求feature对象了

posted @ 2011-10-13 11:37 放屁阿狗 阅读(2199) | 评论 (0)编辑 收藏

啊关的企业在处理用友erp人事数据与税务报税时转换数据时被停滞了,一个小时内完成他的需求
  1 # -*- coding:utf-8 -*-
  2 # soctt.bin created  2011.8.29
  3 # sw2us.com @2011 
  4 #
  5 
  6 import sys,os,os.path,time,struct,traceback,threading,datetime,string,datetime,calendar
  7 import xlrd
  8 
  9 start_year=0
 10 start_month= 0
 11 start_day =1 
 12 end_day = start_day 
 13 
 14 end_year= 0
 15 end_month = 0
 16 
 17 employee_importFile=u'111111111.XLS'
 18 tax_importFile=u'题桥工资格式.xls'
 19 
 20 employee_exportFile=u'empolyees.txt'
 21 tax_exportFile=u'personTax.txt'
 22 employeelistfile='employee_simplelist.txt'
 23 
 24 fixDeduct = 2000.00 #扣除额
 25 
 26 #人员归档
 27 def employeeAchive():
 28     title = u'工号~~姓名~~证件类型~~证件号~~性别~~出生日期~~国家、地区~~开票标志~~申报方式~~职务~~地址~~含税标志~~邮政编码~~调入调离~~备注'
 29     #rowfmt = u"%s~~ %s~~  1       ~~%s    ~~0   ~~%s      ~~142       ~~1       ~~0       ~~    ~~    ~~1       ~~        ~~0       ~~0"
 30     rowfmt = u"%s~~ %s~~  1       ~~%s    ~~0   ~~%s      ~~142       ~~1       ~~0       ~~    ~~    ~~1       ~~        ~~0       ~~0"
 31     rowfmt = rowfmt.replace(' ','')
 32     
 33     wb = xlrd.open_workbook(employee_importFile) 
 34     sh = wb.sheet_by_index(0)
 35     file = open(employee_exportFile,'w')
 36     title = title.encode('gbk')
 37     file.write(title)
 38     file.write('\n')
 39     
 40     file2 = open(employeelistfile,'w'#清单表2
 41     for r in range(1,sh.nrows):
 42         v = sh.row_values(r)
 43         v = map(string.strip,v)
 44         
 45         
 46         birth = ''
 47         try:
 48             y,m,d = v[4].split('-')
 49             birth = "%04d%02d%02d"%(int(y),int(m),int(d))
 50         except:
 51             print u'出生年月空缺 (%s,%s)'%(v[1],v[2])
 52         
 53         txt = rowfmt%(v[1],v[2],v[5],birth)
 54         txt = txt.encode('gbk')
 55         #print len(txt)
 56         file.write(txt+'\n')
 57         
 58         txt = "%s~~%s~~%s\n"%(v[1],v[2],v[5])
 59         txt = txt.encode('gbk')
 60         
 61         file2.write(txt)
 62         
 63     file.close()
 64     file2.close()
 65     
 66 
 67 def precess_parameters():
 68     global start_year,start_month,end_year,end_month,start_day,end_day
 69     
 70     cur = datetime.datetime.now()
 71     start_year = cur.year
 72     start_month = cur.month
 73     #print len(sys.argv)
 74     if len(sys.argv) == 4 and sys.argv[1]=='tax':
 75         start_year = int(sys.argv[2]) 
 76         start_month = int(sys.argv[3])
 77     
 78     start_day = 1
 79     x,end_day= calendar.monthrange(start_year,start_month)
 80     
 81     
 82     
 83 def salaryTax():
 84     global start_year,start_month,end_year,end_month,start_day,end_day
 85     
 86     precess_parameters()
 87 
 88     hashemployee = {}
 89     file = open(employeelistfile,'r')
 90     lines = file.readlines()
 91     file.close()
 92     for line in lines:
 93         line = line.strip().split('~~')
 94         k = line[0]
 95         v = line[2]
 96         hashemployee[k] = v
 97     #以上建立员工查找表
 98     
 99     
100     title = u'证件类型~~证件号码~~税目代码~~含税标志~~所属期起~~所属期止~~天数~~收入额~~扣除额~~应缴税额~~国家地区~~减免税额~~实缴税额'
101     #rowfmt = u"1     ~~%s      ~~010000  ~~1       ~~%s      ~~%s      ~~%s  ~~%s    ~~%s    ~~%s      ~~142     ~~0       ~~%s"
102     rowfmt =  u"1     ~~%s      ~~010000  ~~1       ~~%s      ~~%s      ~~%s  ~~%s    ~~%s    ~~%s      ~~142     ~~0       ~~%s"
103     rowfmt = rowfmt.replace(' ','')
104     
105     wb = xlrd.open_workbook(tax_importFile) 
106     sh = wb.sheet_by_index(0)
107     file = open(tax_exportFile,'w')
108     title = title.encode('gbk')
109     file.write(title)
110     file.write('\n')
111     
112     for r in range(1,sh.nrows):
113         v = sh.row_values(r)
114         
115         v = map(unicode,v)
116         v = map(string.strip,v)
117         sid = '' #身份证编号
118         try:        
119             sid = hashemployee[v[1]]
120         except:
121             print u'处理异常中断: 工号不能匹配! 工号: %s'%(v[1])
122             return 
123             sys.exit(0)
124         start = "%04d%02d%02d"%(start_year,start_month,start_day)
125         end = "%04d%02d%02d"%(start_year,start_month,end_day)        
126         txt = rowfmt%(sid,start,end, end_day-start_day+1,v[22],fixDeduct,v[24],v[24] ) #应发工资 W(v[22])
127         txt = txt.encode('gbk')        
128         file.write(txt+'\n')
129     file.close()
130     
131 
132 if __name__=='__main__':
133     employeeAchive()
134     salaryTax()
135    
posted @ 2011-08-30 11:28 放屁阿狗 阅读(278) | 评论 (0)编辑 收藏

It can be used to solve linear equation systems or to invert a matrix.
高斯消元法用于解决线性代数求多元方程组的解,或者用于求可逆矩阵的逆
嘿嘿,python代码现成可用:
def gauss_jordan(m, eps = 1.0/(10**10)):
  
"""Puts given matrix (2D array) into the Reduced Row Echelon Form.
     Returns True if successful, False if 'm' is singular.
     NOTE: make sure all the matrix items support fractions! Int matrix will NOT work!
     Written by J. Elonen in April 2005, released into Public Domain
"""
  (h
, w) = (len(m), len(m[0]))
  
for y in range(0,h):
    maxrow 
= y
    
for y2 in range(y+1, h):    # Find max pivot
      if abs(m[y2][y]) > abs(m[maxrow][y]):
        maxrow 
= y2
    (m[y]
, m[maxrow]) = (m[maxrow], m[y])
    
if abs(m[y][y]) <= eps:     # Singular?
      return False
    
for y2 in range(y+1, h):    # Eliminate column y
      c = m[y2][y] / m[y][y]
      
for x in range(y, w):
        m[y2][x] 
-= m[y][x] * c
  
for y in range(h-1, 0-1, -1): # Backsubstitute
    c  = m[y][y]
    
for y2 in range(0,y):
      
for x in range(w-1, y-1, -1):
        m[y2][x] 
-=  m[y][x] * m[y2][y] / c
    m[y][y] 
/= c
    
for x in range(h, w):       # Normalize row y
      m[y][x] /= c
  
return True
使用方法 :

If your matrix is of form [A:x] (as is usual when solving systems), items of A and x both have to be divisible by items of A but not the other way around. Thus, you could, for example, use floats for A and vectors for x. Example:
mtx = [[1.0, 1.0, 1.0, Vec3(0.0,  4.0, 2.0), 2.0],
       [2.0, 1.0, 1.0, Vec3(1.0,  7.0, 3.0), 3.0],
       [1.0, 2.0, 1.0, Vec3(15.0, 2.0, 4.0), 4.0]]
if gauss_jordan(mtx):
  print mtx
else:
  print "Singular!"
# Prints out (approximately):
#
# [[1.0, 0.0, 0.0, (  1.0,  3.0,  1.0),  1.0],
#  [0.0, 1.0, 0.0, ( 15.0, -2.0,  2.0),  2.0],
#  [0.0, 0.0, 1.0, (-16.0,  3.0, -1.0), -1.0]]
Auxiliary functions contributed by Eric Atienza (also released in Public Domain):
def solve(M, b):
  """
  solves M*x = b
  return vector x so that M*x = b
  :param M: a matrix in the form of a list of list
  :param b: a vector in the form of a simple list of scalars
  """
  m2 = [row[:]+[right] for row,right in zip(M,b) ]
  return [row[-1] for row in m2] if gauss_jordan(m2) else None
def inv(M):
  """
  return the inv of the matrix M
  """
  #clone the matrix and append the identity matrix
  # [int(i==j) for j in range_M] is nothing but the i(th row of the identity matrix
  m2 = [row[:]+[int(i==j) for j in range(len(M) )] for i,row in enumerate(M) ]
  # extract the appended matrix (kind of m2[m:,...]
  return [row[len(M[0]):] for row in m2] if gauss_jordan(m2) else None
def zeros( s , zero=0):
    """
    return a matrix of size `size`
    :param size: a tuple containing dimensions of the matrix
    :param zero: the value to use to fill the matrix (by default it's zero )
    """
    return [zeros(s[1:] ) for i in range(s[0] ) ] if not len(s) else zero



算法伪代码:
i := 1
j := 1
while (i ≤ m and j ≤ n) do
  Find pivot 
in column j, starting in row i:
  maxi :
= i
  
for k := i+1 to m do
    
if abs(A[k,j]) > abs(A[maxi,j]) then
      maxi :
= k
    end 
if
  end 
for
  
if A[maxi,j] ≠ 0 then
    swap rows i and maxi, but 
do not change the value of i
    Now A[i,j] will contain the old value of A[maxi,j].
    divide each entry 
in row i by A[i,j]
    Now A[i,j] will have the value 
1.
    
for u := i+1 to m do
      subtract A[u,j] 
* row i from row u
      Now A[u,j] will be 
0, since A[u,j] - A[i,j] * A[u,j] = A[u,j] - 1 * A[u,j] = 0.
    end 
for
    i :
= i + 1
  end 
if
  j :
= j + 1
end 
while


posted @ 2011-08-29 02:47 放屁阿狗 阅读(526) | 评论 (0)编辑 收藏

矩阵是个好玩的东西,在平面软件处理的时候,逆矩阵都用来转换鼠标位置到特定的坐标系,教科书是这么写的  M' x ( F x M) = M
numpy 就很简单了: 

from numpy import linalg as LA
form numpy import *
m = mat('1 2 3;4 5 6;7 8 9')
mi = LA.inv(m)
print mi
posted @ 2011-08-28 05:21 放屁阿狗 阅读(470) | 评论 (0)编辑 收藏

sdk自带的ZoomBoxHandler实现的功能地图的ZoomIn
unregisterListeners(),registerListeners() 注册和注销与地图的事件关联
deactiveDrag()函数禁止map的拖动
每一次zoom之后ZoomBoxHandler就失效,每次都必须点击ZoomBox按钮
ZoomBox.mxml定义了触发按钮,点击即刻调用handler.deactiveDrag()

考虑改造这个ZoomBoxHandler的触发规则,比如检测下按 [shift/ctrl] 自动进入zoom状态,[shift]放大,[ctrl]缩小
posted @ 2011-08-16 04:24 放屁阿狗 阅读(371) | 评论 (0)编辑 收藏

从朋友处得到一份2011年的四维地图数据,但是数据是未修正偏差的。花了2周时间加工出了效果
有问题请大家指正

Either scripts and active content are not permitted to run or Adobe Flash Player version 10.0.0 or greater is not installed.

Get Adobe Flash Player

截图 :
posted @ 2011-08-11 19:56 放屁阿狗 阅读(1999) | 评论 (2)编辑 收藏

有点来不及了,今天开始写tax金税开票服务系统的代码,团购的事情与小风交流之后有点清楚
posted @ 2011-07-22 03:33 放屁阿狗 阅读(387) | 评论 (0)编辑 收藏

真的自己没有恒心恐怕要半途而废了
cxoracle版本与oracle instantclient版本 必须严格匹配(花了很多时间)

http://cx-oracle.sourceforge.net/    

oracle 10g
cx_Oracle-5.1-10g.win32-py2.6.msi
instantclient-basic-win32-10.2.0.4.zip
解压instantclient-basic-win32-10.2.0.4.zip ,并将此目录设置为ORACLE_HOME
将instantclient-basic-win32-10.2.0.4目录内的dll拷贝到c:\python26\lib\site_packages
运行oracle_test.py测试是否能连接到远程oracle服务

import cx_Oracle
dsn_tns = cx_Oracle.makedsn('192.168.14.203', 1521,'ORCL')   -- ORCL为远端oracle配置的listener的名称
print cx_Oracle.connect('tax','tax',dsn_tns)
posted @ 2011-07-19 00:54 放屁阿狗 阅读(3324) | 评论 (0)编辑 收藏

学习过MapGuid,MapServer,Qgis等多种开源地图处理服务软件,开发了遵循WMS标准的地图服务,包括wms接入,地图渲染服务。
近1年的时间跑的地图展示都是wms服务器实时请求TileServer进行绘制,Tileserver进程被部署在一台高端的服务器上,同时启动了8个服务进程,访问忙碌的时候机器有点吃不消,就看到cpu那根线飚的很高。
geoserver这个用java做的wms服务器,性能不敢恭维,玩geoserver的时候接触了tilecahce这个开源软件,目前跑啥版本就不清楚了,之前将其研究了个明白,知道自己需要的是什么,所以一切还是得自己写。
对我来讲tilecache不实用的原因有多个:
1.支持过多的cahce 存储方式,什么google的数据库,oracle的也有,虽然代码框架的好,但很多东西都不管用,所以代码维护不够灵活
2.tilecache通过apache提供web的wms服务,然后tilecahe里再请求后端的geoserver服务,产生的cache根据他定 义的一个网格依次按x,y,z的索引存储在文件系统里面,并将图形进行编码分类。这种实现并没有问题,但要知道这些cache出来的图像文件是那么的多且 都零碎,有些图片还够不上一个文件系统基本的一个存储页大小,所以会大量浪费空间;由于文件零碎且多,移动这些文件也是个相当大的问题,一次为了将这些 cahce tile文件从A机器拷贝到B机器尽然花费了1天的时间。

tilecache有这些不如我意的地方,所以之前自己也考虑再写一个tilecache的 backend,将渲染出来的东西直接存储进pgsql数据库,那以后只要导出数据库的tablespace就可以了,嗯!的确可行,也跑了一段时间
最后还是决定放弃tilecahce了,毕竟wms自己已经实现了,要再做个backend也是很简单,做完直接整合进wms服务器。
我考虑采用sqlite来存储这些瓦片图形,由于sqlite处理多线程时天性有点问题,多线程不能共享同一个连接(connection),所以实现的时候在每个线程创建了新的连接,开销是有一些的,那比之前实时请求TileServer要快的多了。
现在wms跑的很开心了,cpu也不忙了,就是累死了硬盘了
一台机器上渲染的地图瓦片数据单独存储在一个文件里面,要部署到另外一台机器也很方便了,只需要拷贝一下就可以了
接着看看将这个sqlite换成pgsql,看看性能哪个更强一点
python代码实现:
 1     def getBitmapTile3(self,renderTile,mapid,res,xy,size):        
 2         if not self.enable:
 3             return None    #表示需要实时请求地图数据
 4         
 5         tile = None
 6         dbconn = sqlite3.connect(self.dbname)
 7         try:            
 8             #dbconn.text_factory = str
 9             cr = dbconn.cursor()
10             cr.execute('select image from tiles where res=? and x=? and y=?',(res,xy[0],xy[1]))
11             r = cr.fetchone()
12             if not r:
13                 tile = renderTile(mapid,res,xy,size)
14                 if tile and tile.pixmap:
15                     b = sqlite3.Binary(tile.pixmap)
16                     print '*'*20
17                     cr.execute(u'insert into tiles (res,x,y,z,image) values(?,?,?,?,?)',(res,xy[0],xy[1],0,b))                    
18             else:
19                 tile = r[0]
20                 self.cacheshooted+=1
21                 print 'shooted ',self.cacheshooted
22         except:            
23             traceback.print_exc()
24             tile = None
25         dbconn.commit()
26         return tile
27 

记得空的时候在flex端写个自动跑地图的程序,不能让机器闲着,没事的时候把全国地图的瓦片自动产生一下,免得在访问地图系统的时候再去产生瓦片!









posted @ 2011-07-11 22:34 放屁阿狗 阅读(1594) | 评论 (0)编辑 收藏

仅列出标题
共25页: First 3 4 5 6 7 8 9 10 11 Last